Backups in Solaris using rsync
It’s day two in our backups week, and today we’ll be looking at automated backups in Solaris. As I mentioned previously, we’ll be using the rsync tool to regularly send important files over to a Linux server for safekeeping (as well as to keep an additional copy locally).
Setting up rsync in a Solaris environment is very easy (and, naturally, is almost identical to setting it up under Linux). We’ll be sending the important files over to Linux, but there’s actually an additional wrinkle: my Solaris box has a very large RAID storage system (this happens to be a Sun E250 with several SCSI disks builtin – so I have about 50 gigs of space left over that I’m not otherwise using), and I’d like to keep another copy of my Linux backups on my Solaris box – backups of backups. It probably sounds crazy, but there’s actually two reasons for this: (1) the Solaris box isn’t in the same place as the Linux backup server, and (2) I need to backup my Linux files somewhere.
So, we’ll be first sync’ing all of our Solaris files over to the Linux box, and then asking for a copy of all the backups under Linux to also be on my Solaris RAID array. Simple.
The first step to getting rsync working under Solaris is to install it (if you don’t already have it installed). Check out www.sunfreeware.com and download the package for your version of Solaris (I’m using Solaris 10 under SPARC). Download the file (it’s in PKG format), and install it (as root):
dpkg –add rsync rsync-2.6.8-sol10-sparc-local.gz
This should place the rsync executable into /usr/local/bin. Be sure to check that /usr/local/bin is in your PATH, and then try running rsync –version to ensure that it works.
Once rsync has been installed, the next step is to configure it. We’re going to be using it in just one mode: as a client, but we’re going to be doing two things with it (pushing files to the Linux box, and then pulling files from the Linux box). First, we need to tell the Linux box that we’d like to send it some files. Open the /etc/rsyncd.conf file (on the Linux server end), and add a new rsync profile (here’s an example):
[zeta]
path=/backups/zeta
uid = ryan
gid = ryan
read only = true
auth users = ryan
secrets file = /etc/rsyncd.secrets
I discuss how to add profiles in a previous post.
Now that the rsync server expects to see files from our Solaris box, the next step is to test it. On the Solaris end, we’re going to send all of the files in /export/home (in other words, all files owned by a user on the Solaris box). Here’s a command to accomplish this:
/usr/local/bin/rsync -vrtpog --password-file=/etc/rsync.secret --delete \
/export/home ryan@10.0.0.2::zeta
Let’s dissect this command a bit. First, the flags:
-v is to be verbose (this will print out what it’s doing and the files that are being backed up to stdout)
-r is recursive, so we get everything in /export/home (and not just one level)
-t preserves file access/modification times
-p preserves file permissions
-og preserves file/group ownership IDs (even if those IDs don’t map to users on other systems)
Next is the password-file argument. As I explained in a previous post, this allows us to save our rsync password in a file rather than having to type it in every time. If you’re just going to be running rsync manually all the time, then it’s better to be prompted for your password. But, since we’ll be automating everything, we’ll need a way for rsync to get the password itself. This is done by creating a text file with your password in it (and just the password – nothing else). I put mine in /etc/ so I’ll remember where it is (and chmod’d it to 600).
The –delete argument tells the Linux box that it’s ok to delete previously backed up files that no longer exist on the Solaris end. Take this out if you want to always keep files around (even if you delete it on one end).
Finally, the remaining two arguments specify where we are reading files from (/export/home) and where they should be written to (the address of the Linux box and the profile we created earlier in /etc/rsyncd.conf).
Try running the command. If everything works properly, you should see print some messages to the screen (such as “building file list”, and many file names). Double-check that the files made it to Linux. Once this is done, you can put it into a crontab and have it run automatically. Here’s an example:
0 5 * * * /usr/local/bin/rsync -vrtpog --password-file=/etc/rsync.secret –delete \
/export/home ryan@10.0.0.2::zeta 1>/backups.log
Putting this into your crontab will execute the backup every night at 5am, transferring all files in /export/home to the Linux box, using the zeta profile. Additionally, I left the verbose flag set and redirected output to /backups.log. This comes in handy, as I then have a file (overwritten daily) that contains the morning’s backup log. Should any errors occur, they get printed to cron, which sends me an email, but all standard operations are logged to this file (and I can double check that important files I worked on the previous day actually made it to the backups).
Now that we have backups from Solaris to Linux working, the next step is to do the reverse, and grab all of the backup files in Linux and dump them onto the extra disk space I have on my Solaris box. It’s very easy, but requires a new profile on the Linux end:
[zeta-backup]
path=/backups
uid = ryan
gid = ryan
read only = true
auth users = ryan
secrets file = /etc/rsyncd.secrets
Notice that the only thing that changed was the path: instead of specifying a directory to dump files into, we specify the directory of files to read from (in this case, my separate disk mounted at /backups). Then, on the Solaris end, we use a very similar command as before:
/usr/local/bin/rsync -vrtpog --password-file=/etc/rsync.secret --delete \
ryan@10.0.0.2::zeta-backups /export/backups
This connects to the Linux box (using the rsync profile zeta-backups) and grabs all the files stored there (in the /backups directory), copying them locally to /export/backups (which is where I mounted that RAID volume). Thus, we now have backups of backups!
Automating this is very easy as well: just add an entry to your crontab:
0 6 * * * /usr/local/bin/rsync -vrtpog --password-file=/etc/rsync.secret –-delete \
ryan@10.0.0.2::zeta-backups /export/home 1>/fullbackups.log
This will run the backup-of-backup rsync command at 6am every day, and log all of the files we backed up to /fullbackups.log.
And there you have it: setting up rsync in Solaris is very easy, and we have an extra layer of redundancy to our backup system (a complete copy of another machine). If you have the disk space and hardware, put a separate machine in another location (say under your desk) and get a complete copy of your files (that may be at your datacenter, for instance). You’ll have an extra copy of your files ready to go should you ever need them.
Tomorrow I’ll take a look at rsync in a Windows environment. There are several key differences, but, with the magic of Cygwin, setup is very much like that under Linux. Stay tuned!














