The 3-2-1 Backup Rule
Every reliable cloud infrastructure relies on the **3-2-1 rule**:
**3** total copies of your data.**2** different storage media types.**1** copy stored entirely off-site.Rclone is an open-source command-line tool that syncs files to over 40 cloud storage providers (AWS S3, Google Cloud, Cloudflare R2, Wasabi) with client-side zero-knowledge AES encryption.
Step 1: Install & Configure Rclone
sudo apt install -y rclone
rclone config
Follow the interactive prompt to connect your S3 bucket credentials.
Step 2: Automated Nightly Backup Script
Create `/usr/local/bin/backup-system.sh`:
#!/bin/bash
set -e
DATE=$(date +%Y-%m-%d_%H%M%S)
BACKUP_DIR="/tmp/backup_$DATE"
mkdir -p "$BACKUP_DIR"
# 1. Dump PostgreSQL / MySQL Database
pg_dump -U postgres -d edutechz > "$BACKUP_DIR/database.sql"
# 2. Archive App Code & Environment
tar -czf "$BACKUP_DIR/app_configs.tar.gz" /etc/nginx /etc/systemd/system
# 3. Encrypt and Upload to Remote S3 via Rclone
rclone copy "$BACKUP_DIR" remote-s3:my-backup-bucket/$DATE
# 4. Clean up local temporary files
rm -rf "$BACKUP_DIR"
Make it executable:
sudo chmod +x /usr/local/bin/backup-system.sh
Step 3: Schedule Cron Execution
Run `sudo crontab -e` and append:
# Run daily at 02:00 AM UTC
0 2 * * * /usr/local/bin/backup-system.sh >> /var/log/backup.log 2>&1