Back to Cloud VPS Documentation

    Backup Strategies

    Best practices for protecting your cloud infrastructure

    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 /restore

    Testing Your Backups

    Backups are useless if they don't work. Regular testing is critical:

    1. Scheduled Tests - Test restores monthly
    2. Document Procedures - Write down restoration steps
    3. Test Different Scenarios - Full restore, single file, database only
    4. Verify Data Integrity - Check that restored data is usable
    5. 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 data

    Backup 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:

    Mission Critical:Cloud snapshots + real-time replication
    Important:Daily cloud snapshots + weekly off-site
    Standard:Weekly snapshots + monthly off-site
    Low Priority:Manual snapshots as needed

    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.