Linux VPS

Backups with rsync

Incremental backups from a HolyCloud VPS to a remote server over SSH, with exclusions and cron scheduling.

~10 min read Beginner #rsync#backup#ssh#cron

rsync copies only changed files from your HolyCloud Linux VPS to another server (second VPS, NAS, or standby machine) over SSH. It is a lightweight solution without a proprietary agent, ideal alongside snapshots in the customer area.

Prerequisites

  • A HolyCloud source VPS (Ubuntu 22.04/24.04 or Debian 12)
  • A destination server reachable over SSH (key or password)
  • Enough disk space on the destination
  • sudo access on the source VPS

Tip: create a dedicated backup user on the destination with access limited to the backup directory.

Step 1: install rsync and prepare SSH

On source and destination:

sudo apt update
sudo apt install -y rsync openssh-client

Generate an SSH key dedicated to backups (no passphrase for cron automation, or passphrase + ssh-agent for more security):

sudo -u backup ssh-keygen -t ed25519 -f /home/backup/.ssh/id_backup -N ""
sudo -u backup ssh-copy-id -i /home/backup/.ssh/id_backup.pub backup@IP_DESTINATION

Test the connection:

sudo -u backup ssh -i /home/backup/.ssh/id_backup backup@IP_DESTINATION "echo OK"

Step 2: first manual sync

Create the target directory on the destination, then run a dry-run to see what will be copied:

sudo rsync -avzn --delete \
  -e "ssh -i /home/backup/.ssh/id_backup" \
  /etc/ /var/www/ /home/ \
  backup@IP_DESTINATION:/srv/backups/vps-prod/

Useful options:

-------- ------
-a Archive (permissions, dates, symlinks)
-v Verbose
-z Network compression
-n Simulation (dry-run)
--delete Remove files on destination missing from source

Run the real copy by removing -n:

sudo rsync -avz --delete \
  -e "ssh -i /home/backup/.ssh/id_backup" \
  /etc/ /var/www/ /home/ \
  backup@IP_DESTINATION:/srv/backups/vps-prod/

Step 3: exclusion patterns

Do not back up system cache, large logs, or temporary mounts. Create /etc/rsync-excludes.txt:

/proc/*
/sys/*
/dev/*
/tmp/*
/run/*
/mnt/*
/media/*
/lost+found
/var/cache/*
/var/tmp/*
*.swp
*.log

Use it like this:

sudo rsync -avz --delete \
  --exclude-from=/etc/rsync-excludes.txt \
  -e "ssh -i /home/backup/.ssh/id_backup" \
  / backup@IP_DESTINATION:/srv/backups/vps-prod-root/

To exclude a single folder without a file:

sudo rsync -avz --exclude 'node_modules/' /var/www/monapp/ backup@IP_DESTINATION:/srv/backups/monapp/

Step 4: schedule with cron

Edit root crontab (or backup user):

sudo crontab -e

Example: daily backup at 3 AM with logging:

0 3 * * * /usr/bin/rsync -avz --delete --exclude-from=/etc/rsync-excludes.txt -e "ssh -i /home/backup/.ssh/id_backup -o BatchMode=yes" /etc/ /var/www/ /home/ backup@IP_DESTINATION:/srv/backups/vps-prod/ >> /var/log/rsync-backup.log 2>&1

BatchMode=yes prevents a cron job from hanging waiting for a password.

Verification

  • Compare data size: du -sh /srv/backups/vps-prod/ on the destination
  • Run a dry-run again: transfers listed should be minimal after the first pass
  • Check /var/log/rsync-backup.log after the cron run

HolyCloud best practices

  • Combine rsync with VPS snapshots in the HolyCloud panel before major upgrades
  • Encrypt sensitive backups (gpg, encrypted storage on the destination)
  • Test a restore at least once (reverse rsync or targeted extraction)

Need help?

Contact HolyCloud support from your customer area if sync fails (firewall, SSH keys, disk space).