📢 LordCloud support has moved to Ballastra — Join now →
Docs

Creating backups

Back up a VPS properly — what to back up, automating it with restic or rsync, and testing restores.

1 min read Some details need confirmation
On this page

A VPS is unmanaged: you are responsible for backing up data inside it. Follow the 3-2-1 rule — three copies, on two kinds of storage, one off-site.

What to back up#

  • Application data and uploads (/var/www, /home, /srv)
  • Databases — dump them; copying live database files is unreliable
  • Configuration (/etc/nginx, /etc/systemd/system, .env files)
  • Docker volumes

Dump databases#

bash
mysqldump --single-transaction --all-databases | gzip > /root/backup/mysql-$(date +%F).sql.gz
pg_dumpall -U postgres | gzip > /root/backup/pg-$(date +%F).sql.gz

Off-site backups with restic#

restic gives encrypted, deduplicated backups to S3-compatible storage, SFTP and more:

bash
sudo apt install -y restic
export RESTIC_REPOSITORY="sftp:user@backup-host:/backups/myvps"
export RESTIC_PASSWORD_FILE=/root/.restic-pass
restic init
restic backup /etc /var/www /root/backup
restic forget --keep-daily 7 --keep-weekly 4 --prune

Automate with cron#

bash
sudo crontab -e
# daily at 03:30
30 3 * * * /root/backup.sh >> /var/log/backup.log 2>&1

Test restores#

A backup you've never restored is a guess. Restore to a temporary directory monthly:

bash
restic restore latest --target /tmp/restore-test
Have a question? Chat with us👋