Server Management

How to Set Up Daily Automated Backups on a Linux Server

Backups you do not test are backups you do not have. This guide covers setting up automated daily backups on a Linux VPS — databases, files, offsite storage — with verification.

March 30, 2025 11 min read NextCode Solutions

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

Method 1: aaPanel Built-In Backup (Easiest)

If you are using aaPanel: Cron → Add Task → Backup Site. Set:

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:

The most important check: Verify backup files actually exist in your offsite storage. Log into Google Drive weekly and confirm the latest backup file is there and has a reasonable file size. An empty or tiny backup file means something went wrong silently.

Related Reading

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