Every server administrator knows backups matter. Most servers still do not have them set up properly. This guide covers the complete backup setup — daily automated backups, offsite storage, and most importantly, testing that restores actually work.
The 3-2-1 Backup Rule
Keep 3 copies of your data, on 2 different storage types, with 1 copy offsite. For a typical VPS: daily local backup + daily offsite (Google Drive/S3) + weekly offsite = covered.
What to Back Up
- MySQL/MariaDB databases: All databases, dumped as .sql files
- Website files: /www/wwwroot/ (aaPanel) or /home/ (cPanel) — everything in your web root
- Configuration files: Nginx configs, PHP configs, cron jobs, SSL certificates
- Email data (if your server handles email)
Method 1: aaPanel Built-In Backup (Easiest)
If you are using aaPanel: Cron → Add Task → Backup Site. Set:
- Backup type: Website + Database (back up both together)
- Frequency: Daily, at 2:00 AM
- Save to: Cloud storage (Google Drive recommended)
- Retention: Keep last 7 copies
Repeat for each site. Also add a separate Database backup task as a redundant database-only backup.
Method 2: Shell Script + Cron (Full Control)
For a complete custom backup script:
#!/bin/bash
# /usr/local/bin/daily-backup.sh
DATE=$(date +%Y%m%d_%H%M)
BACKUP_DIR="/backup/daily"
KEEP_DAYS=7
mkdir -p $BACKUP_DIR
# Backup all MySQL databases
mysqldump --all-databases -u root -pYOUR_PASS | gzip > $BACKUP_DIR/db_all_$DATE.sql.gz
# Backup website files
tar -czf $BACKUP_DIR/www_$DATE.tar.gz /www/wwwroot/
# Backup Nginx configs
tar -czf $BACKUP_DIR/nginx_$DATE.tar.gz /www/server/nginx/conf/
# Delete backups older than KEEP_DAYS
find $BACKUP_DIR -type f -mtime +$KEEP_DAYS -delete
echo "Backup completed: $DATE"
Make executable and add to cron:
chmod +x /usr/local/bin/daily-backup.sh
crontab -e
# Add: 0 2 * * * /usr/local/bin/daily-backup.sh >> /var/log/backup.log 2>&1
Offsite Backup with rclone (Google Drive)
rclone syncs your local backups to Google Drive automatically:
# Install rclone
curl https://rclone.org/install.sh | sudo bash
# Configure Google Drive remote
rclone config
# Follow prompts: New remote → n → name: gdrive → Storage: drive → follow OAuth flow
# Add sync to cron (runs after backup script)
30 2 * * * rclone sync /backup/daily gdrive:server-backups/$(hostname) --min-age 1m
Testing Your Backups
A backup you have never tested is a backup you cannot trust. Test quarterly:
- Database restore test: Create a test database, restore a backup SQL file into it, verify the data looks correct
- File restore test: Extract a backup archive to a temp directory, verify files are intact and readable
- Full restore drill: Once a year, spin up a test VPS and do a complete restore — time how long it takes
Related Reading
- How to Set Up aaPanel on a VPS — backup setup is covered in step 5
- How to Fix a Full Disk on a Linux Server — backup files are a common cause of full disks
Need a Backup System Set Up Professionally?
NextCode Solutions configures automated backups with offsite storage and monthly verification for VPS and dedicated servers.
Set Up My Backups