Note: Well almost all free tools.  I used WinRar's command lines to achive my files, but I looked it up and 7zip (OSS) has command line functionality.

I needed to back up my files on my server.  Up until now, I've been doing it client to server and it hasn't been working all that well.  I wanted something that was local to the server itself, which would push files to a remote location.  The first thing I tried to use was SyncBack's free tool, which I have used on my home machine to sync two drives (External and Internal drives mirrored with important files).  Syncback works well enough for my home machine, but it's FTP functionality needs a ton of work.  With a bunch of small files it would take almost 24 hours to backup the server, which was way too long.  It would also lock up.  I then thought to zip (or rar) everything up (outlined below), and yet Syncback would upload the file, and then upload it again overwriting the existing file ad naseaum.  As a server backup tool, Syncback (the free version) totally sucked donkey balls.

So I had to find something else that would do everything that I wanted to do.  These were 1) Backup my databases 2) Rar up the databases, web files, and SVN 3) FTP it to a remote location and 4) Run 1-3 daily.  I created a batch file named BackupServer.bat to do this.

Step 1 - Backing up Databases

For the first step I wrote my own WinForm application.  It uses SMO, which is new to SQL Server 2005, but is pretty sweet.  Essentially, in my program, you specify the databases you want to backup in the config file, and run the tool.  This will place a 'bak' backup file in the same directory as the tool. 

Download DbTool.zip

Once you have it set you'll need to call it in your batch like so:

C:\Backup\DatabaseBackups\DbTool

Step 2 - Compressing Files

Now that we've got a set of backed up databases, web files, and a svn repository, it'd be nice to compress them for remote transfer.  I used WinRAR which isn't free, but 7Zip is so if you REALLY need free, go that route (plus the 7z format looks enticing...). I added the RAR directory to my environment's path variable (My Computer->Properties->Advanced->Environment Variables)

And then came up with this to compress the Web files (many thanks to Christopher Evans):

echo C:\Inetpub\wwwroot backed up on %date% %time%>_date_.txt
rar a -rr3 -s -u C:\Backup\Sync\Web.rar @backupweb.txt -x@excludeweb.txt
rar c -z_date_.txt C:\Backup\Sync\Web.rar
del _date_.txt

This little bit of comand line magic does the following:

Line 1 inserts the text "C:\SVN backed up on <date and time>" into _date_.txt. 

Line 2 updates [-u] (or creates) a solid [-s Good for compressing large numbers of files] Web.rar file with a 3% recovery record [-rr3] in the C:\Backup\Sync\ directory.  backupweb.txt contains all the files and folders I want to backup 'C:\Inetpub\wwwroot' and excludeweb.txt contains all the files and folders I do not want to compress:

C:\Inetpub\wwwroot\*.wma
C:\Inetpub\wwwroot\*.wmv
C:\Inetpub\wwwroot\*.mp3
C:\Inetpub\wwwroot\*.mov
C:\Inetpub\wwwroot\*.mpg
C:\Inetpub\wwwroot\*.avi
C:\Inetpub\wwwroot\*.ram
C:\Inetpub\wwwroot\*.zip
C:\Inetpub\wwwroot\*.rar
C:\Inetpub\wwwroot\*.log
C:\Inetpub\wwwroot\*.bak
C:\Inetpub\wwwroot\*.exe
C:\Inetpub\wwwroot\*.msi
C:\Inetpub\wwwroot\*.csv
C:\Inetpub\wwwroot\*.mdf
C:\Inetpub\wwwroot\*.ldf

This keeps my Web.rar file around 300MB's.  If I had included the above files it would have topped out around 1GB.  Since those files don't change a lot, and I already have a local copy, there's no sense in wasting bandwidth and taking up the extra time to back these up each night.

Line 3 Add a comment "C:\SVN backed up on <date and time>" to the RAR file from the _date_.txt file.

Line 4 then deletes the _date_.txt file.

I did this for all three groups of files that I wanted to backup.

Step 3 - FTP Files to Remote Location

Since I wanted no added cost, and I promised you free, I wanted to download the files to my local machine.  I signed up for an free account at no-ip.com, and setup the domain <yourNameHere>.servebeer.com to point to my machine.  I downloaded their free no-ip.com dynamic dns update which will keep my dynamic IP address in sync with the domain.  I then went and downloaded FileZilla's server software (OSS, so also free) and set it up with an account to a backup folder on my local machine (h:\Backup) with full rights to only that folder.  I also restricted access to only my server's IP, so I felt a little safer.  I installed FileZilla's client software on my server (kinda backwards, but it works!) and then configured the firewalls on both client and server and tested the connection out.  I created a new Site in the Site Manager called "Backup" which I use below in the command line.

Once everything was in working order it was time to again go to the command line.  FileZilla itself notes that it isn't a full blown automation app, but it's free so what the heck (ref: FileZilla command line args).  I went in and added FileZilla to the machines PATH variable to make it just a little easier.  The following opens FileZilla client, transfers single files (multi-file transfer was disabled with version 2 for some wierd reason) and then closes the application.

filezilla -s Backup -u "C:\Backup\Sync\<fileName>" ftp://<username:<password>@<yourNameHere>.servebeer.com -overwrite -close

Why not just use DOS FTP you say?  I tried, and tried, and tried some more.  You're welcome to it if you want, but in my case it worked some times and didn't other times.  FileZilla worked all the time in my tests, with no hassles.  It was also easier to test connectivity with.  It can be done without FileZilla, but don't say I didn't warn you.

The line will open the Backup site [-s] and upload [-u] the file specified to the remote ftp server specified.  If the file exists (it does) it will overwrite it automatically [-overwrite] and then when completed it will close down the FileZilla client [-close].

I created another bat file call FTPFilesToRemoteLocation that contained each individual FTP backup call and included that in my BackupServer batch file.

Step 4 - Schedule it to run daily

For this I used Window's built in Scheduler.  Point to Control Panel->Scheduled Tasks->Add Scheduled Task

Click next

Browse, and select the BackupServer.bat file

Give the schedule process a name, and select "Daily".

Give it a start time when the server is most likely not being used.  Give it the start date you want it to begin (today).

Enter your username and password that this will run under:

and then Finish out the wizard.  All done!

My batch file

After all is said and done, here was the resulting batch file:

C:\Backup\DatabaseBackups\DbTool

echo C:\SVN backed up on %date% %time%>_date_.txt
rar a -rr5 -s -u C:\Backup\Sync\Svn.rar @backupsvn.txt
rar c -z_date_.txt C:\Backup\Sync\Svn.rar
del _date_.txt

echo Databases backed up on %date% %time%>_date_.txt
rar a -rr5 -s -u C:\Backup\Sync\Databases.rar @backupdb.txt
rar c -z_date_.txt C:\Backup\Sync\Databases.rar
del _date_.txt

echo C:\Inetpub\wwwroot backed up on %date% %time%>_date_.txt
rar a -rr3 -s -u C:\Backup\Sync\Web.rar @backupweb.txt -x@excludeweb.txt
rar c -z_date_.txt C:\Backup\Sync\Web.rar
del _date_.txt

C:\Backup\FTPFilesToRemoteLocation

File Structure