Rsnapshot on OSX

Rsnapshot is a backup solution for Unix machines including Linux and OSX, it supports many great features including full backups with the size of only incremental backup, it also support backing up local and remote machines.

Check my previous post for more details about it, Backup Journey to rsnapshot

Install Rsnapshot

The easiest way to install unix programs in OSX is to use Homebrew, after installing Homebrew install rsnapshot and needed programs:

$ brew update
$ brew install rsnapshot
$ brew install coreutils

“coreutils” is needed because “cp” command installed with OSX doesn’t support GNU “cp” options needed for rsnapshot.

Configuration

I will be running rsnapshot from user account and not root user, I will be using my user “rayed”:

$ mkdir /Users/rayed/rsnapshot
$ cat > /Users/rayed/rsnapshot/rsnapshot.conf << EOF
#################################################
# rsnapshot.conf - rsnapshot configuration file #
#################################################
#                                               #
# PLEASE BE AWARE OF THE FOLLOWING RULES:       #
#                                               #
# This file requires tabs between elements      #
#                                               #
# Directories require a trailing slash:         #
#   right: /home/                               #
#   wrong: /home                                #
#                                               #
#################################################
config_version	1.2

snapshot_root	/Users/rayed/rsnapshot/

cmd_cp		/usr/local/bin/gcp
cmd_rm		/bin/rm
cmd_rsync	/usr/bin/rsync
cmd_ssh		/usr/bin/ssh
cmd_logger	/usr/bin/logger

retain		hourly	4
retain		daily	7
retain		weekly	4
retain		monthly	3

verbose		2
loglevel	3
logfile		/Users/rayed/rsnapshot/rsnapshot.log
lockfile	/Users/rayed/rsnapshot.pid

# Backup local machine
backup		/Users/rayed/	localhost/
# Backup remote machine
backup		rayed@example.com:/home/rayed/	example.com/
EOF

Important notes about the configuration files:

  • Use TABs not spaces between elements.
  • Directories require a trailing slash, i.e. /home/ not /home
  • On OSX we replaced “cmd_cp” from “/bin/cp” to “/usr/local/bin/gcp” to support rsnapshot options.
  • For remote machine backup, make sure you use ssh keys, Rsnapshot can’t use passwords.

Running rsnapshot

To test your setup try the following command:

rsnapshot -c /Users/rayed/rsnapshot/rsnapshot.conf hourly

When everything works fine, you need to configure “rsnapshot” to run periodically from cron, install the following line:

$ crontab -e
:
# RSnapshot
0 */6 * * *	/usr/local/bin/rsnapshot -c /Users/rayed/rsnapshot/rsnapshot.conf hourly
30 3 * * *	/usr/local/bin/rsnapshot -c /Users/rayed/rsnapshot/rsnapshot.conf daily
0  3 * * 1	/usr/local/bin/rsnapshot -c /Users/rayed/rsnapshot/rsnapshot.conf weekly
30 2 1 * *	/usr/local/bin/rsnapshot -c /Users/rayed/rsnapshot/rsnapshot.conf monthly

After few hours double check your setup by making reviewing the log file “/Users/rayed/rsnapshot/rsnapshot.log”, and check the rsnapshot root directory for your backups, you should have something like:

$ ls -l /Users/rayed/rsnapshot/
hourly.0
hourly.1
hourly.2
hourly.3
daily.0
daily.1
:

10 thoughts on “Rsnapshot on OSX”

  1. Hello, and thanks so much for sharing your info with this post (I loved the ‘backup journey’ post too btw).

    I am hitting a roadblock however… Specifically, “/usr/local/bin/gcp: cannot create hard link … Operation not supported”.
    ERROR: /usr/local/bin/gcp -al /Volumes/backup1/rsnapshot/hourly.0 /Volumes/backup1/rsnapshot/hourly.1 failed (result 256, exit status 1). Perhaps your cp does not support -al options?

    Might you have a word of advice?
    I had thought that by installation gcp I was all set to avoid this type of problem. 🙁

    shawn – from Lausanne

  2. Hello Shawn,

    Thank you for the nice words, glad you find it useful 🙂

    Why don’t you try to run the command manually from the terminal and see what kind of error you would get?
    /usr/local/bin/gcp -al /Volumes/backup1/rsnapshot/hourly.0 /Volumes/backup1/rsnapshot/hourly.1

  3. I’m having the same problem as above. When I try to run the command manually. I receive the following error:

    /usr/local/bin/gcp: cannot create hard link ‘/Volumes/ServerBackup/hourly.1/var/www/icons/poweredby.png’ to ‘/Volumes/ServerBackup/hourly.0/var/www/icons/poweredby.png’: Operation not supported

  4. I think it is related to the remote volume not supporting hard links, try the same command on local files to see if it works.

  5. @Rayed, Thanks for helping us out/reactivity on our “gcp: cannot create hard link … Operation not supported” issue.

    My HFS+ external disk theoretically supports hard links. I also empirically validated this by doing this successfully:
    $ cd /Volumes/backup1
    $ touch this
    $ ln this that
    $ ls -lagi this that
    20514707 -rw-r–r– 2 staff 0 Jun 29 13:16 that
    20514707 -rw-r–r– 2 staff 0 Jun 29 13:16 this

    As you see, no errors came up… and those inode numbers are identical. So I’m pretty sure hard links are working here.

  6. Hi, I have been using rsnapshot on a few macs on an NFS linux server without problem. But recently on one mac, I stated getting the same cannot create hard link problem. The thing is most of the files get hard linked, only a few seem to get a special “no hard link” flag. One file that is a “._.DS_Store” file in a lot of directories and the other files start with “._”

    My best option seems to be to not backup files that start with ._

  7. @Richar
    I haven’t had any issues with rsnapshot on the same disk like the one you have, but it was causing some issues with time machine, since I started using both, time machine backups takes few hours to finish, I am guessing time machine keep discovering new file generated from rsnapshot and start over.

    How about configuring time machine to backup to NFS on Linux?

  8. I don’t use time machine on those mac.s The reason I use rsnapshot is so I don’t have several mac trying to backup every hour on the hour on the same server. It is annoying not to be able to space out time machine. Rsnapshot is more useful in a network of several Mac with a single backup server.

    My backup is not on the same disk, I’m doing an rsnapshot of the /Users directory to an NFS server which I mounted as /Backup. From what I observed, it seems that once a file with a name that starts with ._ on an NFS mounted directory, Mac OS won’t allow a hardlink of the file. If I rename the file to something else, I can do the hardlink. I might search to see if there is a special mount/MacOS/NFS flag I can add to allow the hardlinks.

  9. Hello, thanks for sharing this.

    I got everything working and RSnapshot to save on the same disk for testing purpose. Although now I have a Time Capsule which I no longer use as a backup device or router, it’s setup as a bridge just for storage.

    Would you know how I can use RSnapshot to save to the time capsule drive? I tried to put it as a remote machine on the rsnapshot.conf “backup 192.168.1.22:/Users/gldtn/ localhost/”

    192.168.22 being the time capsule IP

    Had no luck there.. any ideas?

  10. It seems Rsnapshot takes a long time too actually start to report what is backing up on OS X Sierra. In previous OS same conf file would almost immediately reported what it was being backed up. Or could it be there is more files in the volume to be backed up.

Leave a Reply

Your email address will not be published. Required fields are marked *