A solid backup strategy is essential for data protection and disaster recovery. This guide covers various approaches to backing up your cloud instances.
Backup Methods
1. Cloud Snapshots
Best for: Full instance backups and disaster recovery
Pros:
- Complete system backup
- Quick to create and restore
- Integrated with Cloud Control Panel
Cons:
- Costs storage fees
- Slower for large instances
- All stored in same region
2. File-Level Backups
Best for: Specific files, databases, and configurations
Pros:
- Faster for small datasets
- Can backup to external storage
- More flexible and portable
Cons:
- Requires more setup
- Doesn't capture full system state
- Manual restoration more complex
3. Database-Specific Backups
Best for: MySQL, PostgreSQL, MongoDB databases
Pros:
- Application-consistent backups
- Can backup while database is running
- Easy to test and restore
Cons:
- Requires database-specific tools
- Doesn't backup system files
- Need separate strategy for other data
The 3-2-1 Backup Rule
Follow the industry-standard 3-2-1 rule:
- 3copies of your data (1 primary + 2 backups)
- 2different storage types (e.g., cloud snapshot + external)
- 1copy stored offsite/off-platform
Automated Backup Scripts
Basic File Backup with rsync
#!/bin/bash
# /usr/local/bin/backup.sh
BACKUP_DIR="/backup/$(date +%Y%m%d)"
SOURCE="/var/www /etc /home"
mkdir -p $BACKUP_DIR
rsync -avz --delete $SOURCE $BACKUP_DIR
# Optional: Upload to remote storage
# rclone copy $BACKUP_DIR remote:backups/MySQL Database Backup
#!/bin/bash
# /usr/local/bin/mysql-backup.sh
BACKUP_DIR="/backup/mysql/$(date +%Y%m%d)"
MYSQL_USER="backup_user"
MYSQL_PASS="secure_password"
mkdir -p $BACKUP_DIR
# Backup all databases
mysqldump -u$MYSQL_USER -p$MYSQL_PASS --all-databases \
--single-transaction --quick --lock-tables=false \
> $BACKUP_DIR/all-databases.sql
# Compress
gzip $BACKUP_DIR/all-databases.sql
# Delete old backups (keep 7 days)
find /backup/mysql -type d -mtime +7 -exec rm -rf {} +PostgreSQL Database Backup
#!/bin/bash
# /usr/local/bin/postgres-backup.sh
BACKUP_DIR="/backup/postgres/$(date +%Y%m%d)"
mkdir -p $BACKUP_DIR
# Backup all databases
su - postgres -c "pg_dumpall" > $BACKUP_DIR/all-databases.sql
# Compress
gzip $BACKUP_DIR/all-databases.sql
# Delete old backups (keep 7 days)
find /backup/postgres -type d -mtime +7 -exec rm -rf {} +Schedule with Cron
# Edit crontab
crontab -e
# Daily backup at 2 AM
0 2 * * * /usr/local/bin/backup.sh
# MySQL backup at 3 AM
0 3 * * * /usr/local/bin/mysql-backup.sh
# Weekly offsite sync on Sunday at 4 AM
0 4 * * 0 rclone sync /backup remote:backups/Off-Platform Backup Solutions
Using rclone (Recommended)
Rclone supports many storage providers:
# Install rclone
curl https://rclone.org/install.sh | bash
# Configure (interactive)
rclone config
# Sync backups to remote storage
rclone sync /backup remote:backups/
# Or use for incremental backups
rclone copy /backup remote:backups/$(date +%Y%m%d)Rclone supports: AWS S3, Backblaze B2, Google Drive, Dropbox, and 40+ others.
Using Restic (Encrypted Backups)
# Install restic
apt install restic
# Initialize repository
restic init --repo /backup/restic
# Create backup
restic backup --repo /backup/restic /var/www /etc
# List snapshots
restic snapshots --repo /backup/restic
# Restore
restic restore latest --repo /backup/restic --target /restoreTesting Your Backups
Backups are useless if they don't work. Regular testing is critical:
- Scheduled Tests - Test restores monthly
- Document Procedures - Write down restoration steps
- Test Different Scenarios - Full restore, single file, database only
- Verify Data Integrity - Check that restored data is usable
- Measure Time - Know how long restoration takes
Quick Restoration Test
# Create test instance from snapshot
# 1. Create snapshot in Cloud Control Panel
# 2. Launch new instance from snapshot
# 3. Verify services start correctly
# 4. Test application functionality
# 5. Delete test instance
# Test database backup restoration
mysql < backup.sql
# Verify tables and dataBackup Best Practices
- Automate Everything - Manual backups will be forgotten
- Multiple Locations - Don't keep all backups in one place
- Encrypt Sensitive Data - Especially for off-site backups
- Monitor Backup Status - Set up alerts for failed backups
- Document Recovery - Write procedures before you need them
- Retention Policy - Keep daily for 7 days, weekly for 4 weeks, monthly for 6 months
- Test Regularly - Untested backups are not backups
Recovery Time Objectives
Plan your backup strategy based on acceptable downtime:
Remember: The best time to implement a backup strategy is before you need it. Start simple and expand as your needs grow. Even basic automated backups are infinitely better than none.
