Skip to content

Using rsync for Windows backup

OK, so this is a little less about crossing over between programming and system administration, and more about applying *nix tools to a Windows environment. The problem? We recently switched to a new backup system at work, and no longer have Windows client licenses available to us. Since most of the data that our Windows users produce lives on network attached storage rather than the Windows systems themselves, this isn’t a huge deal, but we do want to backup our Active Directory server, as well as a few one-off systems. Rather than shelling out the cash for some extra clients, I decided to look into using rsync to get the data from Windows onto the NAS.

I’ve looked at rsync+win32 in the past, and usually came away disappointed. There are a lot of rsync and rsync-like products for win32, and some of them are quite good. However, my requirements were:
  • It must use the rsync protocol, not an imitation or ‘improved’ protocol
  • the rsync conversation must be tunnelled over ssh
  • authentication must be done using ssh keys
  • backups should run on a scheduled basis, whether users are logged in or not
  • status emails must be sent after each backup
This narrowed the field quite a bit; ssh support was rare, and key-based authentication effectively limited me to using a cygwin-based solution. I almost gave up at this point and started evaluating other ways move move the data, because I’ve never been a big fan of maintaining cygwin installations; no matter how elegant a cygwin solution is, it always ends up feeling like a hack to me. However, after giving it some more thought, I decided to see how far I could strip down a cygwin installation, down to just the binaries and dlls needed to actually perform a backup. The key point for me was the last requirement I had — only one of the rsync-like systems I’d come across offered status emails, whereas I figured using a micro-cygwin installation would allow me to include things like email pretty easily. This didn’t end up working exactly as I had expected, because cygwin’s SMTP support isn’t as good as I’d expected it to be, but even so, it was enough to convince me to keep going.
Actually working out the nuts and bolts of the script took me a bit, but wasn’t terribly difficult; I did a cygwin install, then started copying out into a new directory the executables I’d need (bash, ssh, rsync, etc) and tried running them. Then I actually tried to run them; one after another they started complaining about dlls, but once I got the half dozen or so required dlls, things started falling into place. I generated an ssh key, prepopulated a known_hosts file for ssh, and started rsyncing files up to the server. Then I tried to email out my log file, and ran into a brick wall; if there’s a lightweight way to do SMTP from cygwin, I haven’t found it. My solution was to cheat; since I was already using ssh connections to a full-fledges *nix server, I just made one more connection once I was done and piped the log file to mail.
backup.sh

Categories: Random.

Tags: , , , ,

Comment Feed

No Responses (yet)



Some HTML is OK

or, reply to this post via trackback.