Knowledgebase article

How to back up your server

On an Unmanaged Server, you hold the keys, and the backups are your responsibility too. A server without backups is a love story without photos: one bad day and the memories are gone. Here's a simple, reliable plan.

The golden rule: 3-2-1

  • 3 copies of your data
  • on 2 different kinds of storage
  • with 1 copy off the server (another server, cloud storage, or your computer)

A backup stored only on the same server doesn't help if the disk fails.

What to back up

  • website files (e.g. /var/www or /home)
  • databases
  • configuration files (/etc)
  • anything custom you've built

Back up databases

MySQL / MariaDB:

mysqldump --all-databases --single-transaction | gzip > /backup/db-$(date +%F).sql.gz

Back up files

tar -czf /backup/files-$(date +%F).tar.gz /var/www /etc

Copy backups off the server

To another server with rsync:

rsync -avz /backup/ user@backup-server:/backups/myserver/

Or use rclone to send backups to cloud storage (Google Drive, Backblaze, S3 and others): see rclone.org for setup.

Run it automatically

Put the commands in a script, e.g. /root/backup.sh, make it executable (chmod +x /root/backup.sh), then schedule it with crontab -e:

30 2 * * * /root/backup.sh > /dev/null 2>&1

That runs every night at 2:30. Also delete old backups so the disk doesn't fill up:

find /backup -type f -mtime +7 -delete

Test your backups

Once a month, try restoring a backup to make sure it actually works. An untested backup is only a hope.

Managed Server?

With cPanel/WHM, go to Backup > Backup Configuration in WHM to schedule automatic backups, and choose a remote destination under Additional Destinations. Or ask Romeo to set it up for you.

Was this answer helpful?

Related articles

Still stuck? Romeo's got you.
Our support team replies around the clock, real humans who know your server.