rsync and the Hard Link Limitation

I’ve been setting up a new backup regime on a hosted server that I’m helping to maintain.

One of the key issues right now is that it is there isn’t a solid provided backup regime, so I’ve spent the day playing around with different Linux backup solutions trying to get to the bottom of a simple, yet robust way of backing up.

I like rsync, but the problem is that you can’t use it’s hard linking feature over secure shell. As such, incremental backups are a pain.

I was about to give up on it, and work out a convoluted tar process when it occurred to me that the hard links might still be possible.

And to that end, I wrote this script:




# End of options

# Create mount point directory
if [ -d $SSHFS_MPOINT ]; then
        #Do nowt
        echo "Creating sshfs mount point:" $SSHFS_MPOINT;
        mkdir -p $SSHFS_MPOINT

# Mount backup folder

# Now carry out the backup using hard links
rsync --link-dest=$LOCAL_BACKUP_FOLDER --compress --verbose --times --owner --group --ignore-times --links --perms --recursive --size-only --delete --force --numeric-ids --stats $SSHFS_MPOINT $LOCAL_BACKUP_FOLDER.`date +%F.%T` >> /var/log/rsync_backup.log

# Once done, unmount the remote machine
fusermount -u $SSHFS_MPOINT

exit 0;</code>

Essentially, I’m using FUSE and SSHFS to mount the file system to my local server. From here, I run the backup as though the rsync is carried out locally on the machine. Because the existing backup directory can be accessed locally, there isn’t a problem using the hard links feature.

Of course, the prerequisites are that you have FUSE and SSHFS installed on your system, and that there is an SSH key pair between your machine and the remote server to allow for seamless logon.

You also need at least one backup created in the $LOCAL_BACKUP_FOLDER directory before the script will work.

So far, this seems to be working nicely on a daily basis.