FreeNAS Box Part 2 - rsync
Using rsync for mirroring data to the FreeNAS Box
Using rsync/rsyncx for mirroring data on Mac OS X
Time Machine is a great way to keep your Mac backed up and for keeping a revision history of your files, but it has a one-for-all configuration approach, isn't intended to have the backup shared and it doesn't offer a solution to keep information synced between multiple PCs/Macs, .
To get around this, I turned to rsync. With rysnc I'm offered more control over which folders/files I want to back up, how they're backed up or refreshed and I can configure several scripts to run with cron. Rsync is also supported on other platforms, so this brings in Windows and Linux into the pool of resources.
In my example scenario, which I'm using at home, I've setup a simple push operation of my iPhoto Library from my Macbook Pro to my new FreeNAS box. I had hopes to share my iPhoto Library off of the FreeNAS box, but I found that iPhoto just doesn't behave very well over networked storage.
Later on, this environment will be extended onto another Mac and each one will be configured to run a pull script first, as the FreeNAS is the master, and a subsequent push operation. Hopefully this should keep changes/additions from each Mac synced up.
Configure FreeNAS as a Rsync Daemon
- Hover over the "Services" tab, select "RSYNCD"
- On the "Server" configuration tab, check the "Enable" box and configure as follows:
- Read Only: leave at the default of no, we'll be writing to our rsync module
- Map to user: selection box, you can leave this as guest or select a user you've already configured on the FreeNAS box.
- TCP port: leave at the default of 873
- Maximum Connections: Leave at the default
- MOTD: you can ignore
- Click the rsync "Server Modules" tab to add a share to rysnc
- Click the "+" symbol to add a module
- Name: This is what the rsync client will use to connect. In my case I used iPhoto
- Comment: Type in a short description or purpose
- Path: browse to server backup location
- Others:
- Click the Save button
Create Rsync Script on the client (Macbook Pro)
Mac OS X ships with a version of rsync already installed. You can also download Rysncx which is a GUI tool for rsync and it ships with a version of rsync compiled with support for resource forks which is a part of Apple's filesystem HFS+. As of 10.4 however, Apple ships a version of rsync that supports this. This is a moot pint as we'll be syncing via SMB so either will work, but the GUI has a script generator which can make your life easier.
Our rsync command will be set as follows:
time /usr/local/bin/rsync -azv "$IPHOTO_SRC" $NAS_USER@$NAS_URL::$RSYNC_DEST
- The time command at the beginning will measure how long it takes for rsync to complete its operation.
- Next is the the rsync command. I specified the path to the rsync installed with rsyncx. You can use just rsync if you chose not to install rsyncx.
- Switch operators
- -a performs an archive operation, which will recursively iterate through the entire iPhoto library
- -z enable compression
- -z enables verbose output, which can be helpful for logging and debugging
- $IPHOTO_SRC is the location of my iPhoto Library. This is where the script generator is useful as it'll insert escape sequences for special characters in bash
- $NAS_USER is the user we set in FreeNAS if we didn't use guest
- $NAS_URL is the domain name or IP address of your FreeNAS box
- The double-colon (::) tells rsync to look for a module, which is $RSYNC_DEST
- NOTE: this is the module name we set up earlier in FreeNAS
Save this command to a file (textedit) if you didn't use rsyncx script generator and you'll be able to run it through the terminal.
Configure the script to run with cron
Cron is the job scheduler in the Unix/Linux/FreeBSD world. The rsyncx tool edits the main crontab file. I prefer to edit the crontab file for the user. This is done with the -e flag.
- Open terminal
- Type crontab -e
- Type i to enter insert mode
- Specify the date/time you want to run the command
- Type the path to the command
- Do esc, wq
NOTES/LINKS
-Rsync is
NOT
a perfect backup solution. As noted in this comment (
http://www.engadget.com/2007/03/21/how-to-automatically-back-up-your-computer/comments/4073491/
) if there is data corruption, rsync
WILL
copy that over as well. In this instance rsync is only being used to ensure data is the same across multiple machines. This should be partnered with another backup solution (Time Machine)
-For more information about rsync see the Samba's documentation:
http://www.samba.org/ftp/rsync/rsync.html
-Consult the FreeNAS userguide for the rsync daemon configuration and suggested Windows clients (This is for the old version, but still relevant):
http://www.freenas.org/downloads/docs/user-docs/FreeNAS-SUG.pdf
-Download a copy of RsyncX from here (current version is 2.1):
http://www.tucows.com/preview/290179
-Follow news about FreeNAS on twitter.com/@freenas