rsync backup with hard link incrementals.

Submitted by cliff on Tue, 04/02/2020 - 16:37

For quite some years I've been using an rsync script to make my backups. You can find it here. It basically makes an incremental daily backup and uses hardlinks for files that have not changed to preserve diskspace.

Howto use it

The basic syntax for backup.sh is:

backup.sh <hostname> <remote_root_path> <backup_path>

Locate some server you have and make a new directory on the volume you wish to use for backups. In my examples we will be using /backup.

  • Move the script to /backup/backup.sh
  • Add a file named /backup/backup.exclude which states all paths that should be skipped when running a backup (e.g. /sys, /dev, /proc)
  • Make a new folder for every machine you want to backup (I suggest using hostnames)
  • Add a new folder in every machine folder called seed (This is used for the initial incremental, after the first backup has been run it can be removed)
  • Add a new script /backup/backup-all.sh which contains something like this:
#!/bin/sh
if [ -e /backup/backup.sh ]; then 
  /backup/backup.sh server1.oisec.net /opt /backup/server1.oisec.net
  /backup/backup.sh server2.oisec.net / /backup/server1.oisec.net
else
  echo "backup.sh does not exist"
  exit
fi
  • Generate a ssh key for the root user on your backup machine.
  • Deploy the ssh key to all machine that have to be backupped (for the root user). I suggest using ssh-copy-id.
  • Run /backup/backup-all.sh to start initial backups (this might take a while)
  • Add a cronjob to run /backup/backup-all.sh on a daily basis.
  • Profit

At the moment there is no cleanup in the script, so you manually have to check if there is still enough disk space available for new backups.