Iteratively backing up a linux server to a windows server via SSHMar 17th, 2012 | By admin | Category: Internet, Linux / Freebsd
Ok, so I know that if you are anything like me that you know all about cygwin and rsync but you’re thinking to yourself that it’s kind of overkill to install cygwin in it’s entirety just to be able to use rSync. Surely there are windows based applications out there that can do the job lighter and more effiently. Things like deltacopy, Syncrify(2 great tools by a great company btw), or unison, or Cwrsync (it’s not free anymore) have to be able to do the trick right? Right!?!
I spent the entire bloody day going through them all, trying them all out, seeing what they can do and what they can’t do and while they look snazzy and can do a great many of things, iteratively backing up files from a linux server via ssh onto a windows XP server is not one of them. So save yourself the time, stop looking for that light weight solution and take it from me. INSTALL cygwin with rsync and openssh and set it up like you would if it were a native linux box. It’s the single best way to handle that first of all, but secondly it’s the only way you are going to accomplish this.
For the record out of all the software I tested deltacopy and Syncrify were the best. Which is great because I need to setup automated backups of 2k3 servers to this same XP server so I’ll definitely be going with Syncrify on this.
So I’m not going to explain how to run rsync, there’s plenty to do for that but what I will show you is the command you are going to need to feed into windows scheduled tasks to have this thing run properly every hour or 2 or whenever. Oh speaking of that to automated this don’t bother with a cron, you’re in windows so use it’s “cron” and go into settings/control panel/windows scheduled tasks and open it up(don’t click on add new task). With the window open right click on the empty space and click on new. It will create the icon for you to name, right click it, go into properties and you can set it up manually whihc you will need to do as the wizard doesn’t let you paste in a custom command, you have to select one from the list.
As for that custom command it should look something like this:
c:\Cygwin\bin\bash.exe -l -c ‘/bin/rsync -avpl –delete -e “ssh -p 22” USERNAME@SERVERADDRESS:/path/to/the/shit/you/want/to/backup /cygdrive/DRIVE_LETTER/path/to/destination/‘
So just to make sure it’s as clear as mud the -e “ssh -p 22” is where you can specify the port if you use custom ssh ports.
SERVERADDRESS can be the domain or the IP
The last thing that you should note is the use of ‘ and ” in that command. Everything after -c needs to be surrounded in single quotes so that you can put shit like -e in there whose variables require double quotes. Put double quotes around everything after -c and you’ll be seeing error messages.
That should do it, for the ‘start in’ variable in the scheduled task window it should be c:\Cygwin\bin which it will probably default to if you leave it blank and that’s that!
As long as the server is running you’ll have a nice backup going every day or hour or whenever without too much of a fuss and best of all it’ll use rsync which means it’ll be iterative and lean. Huzah!