🔁 Automatic Backup on VPS
Regular backups are critical for the safety and stability of any project. Data loss due to failure, hacking, or human error can be devastating. In this article, you'll learn how to configure automatic backups on your VPS using cron, rsync, tar, and remote storage.
🛠 What Can Be Backed Up
- 📂 Website files (HTML, PHP, CMS)
- 🗄 Databases (MySQL, PostgreSQL)
- ⚙ Configuration files (/etc)
- 📧 Mailboxes (if mail is configured)
- 🔐 Keys, SSL certificates, and crontab
⏱ Cron Backup Example
Create a bash script /root/backup.sh
:
#!/bin/bash DATE=$(date +"%Y-%m-%d") BACKUP_DIR="/backups/$DATE" mkdir -p $BACKUP_DIR # Website and DB backup tar -czf $BACKUP_DIR/site.tar.gz /var/www/html mysqldump -u root -pYOURPASS dbname > $BACKUP_DIR/db.sql # Remove old backups find /backups/* -mtime +7 -exec rm -rf {} \;
Add to crontab:
0 3 * * * bash /root/backup.sh > /dev/null 2>&1
The script will run every day at 3:00 AM and keep backups for 7 days.
☁ Remote Storage and Cloud
- 🗃 Use
rsync
to send backups to another server - 🔐 Configure backups to FTP, SFTP, or cloud (Yandex.Disk, Dropbox, AWS S3)
- 🧪 Check checksums and file integrity regularly
- 🛑 Do not store backups only on the same VPS without replication
📌 Best Practices from Bit.Hosting
- 🗓 Run backups every night
- 🧯 Test restore procedures at least once a month
- 🧩 Store backups in multiple locations (local + cloud)
- 🔒 Encrypt sensitive data before exporting
If you're unsure how to implement automatic backups on your VPS — contact Bit.Hosting support. We’ll help you set up a secure and reliable backup! 💾