Recently I found this excellent blog post on using Amazon S3 to backup your server, that got me thinking about making a specific version for backing up Subversion on a Windows Server.
A fully automated backup script that would backup all the repos we have directly to Amazon S3, with a cost of zero to $1 a month why wouldn’t you!!

Five Steps to Backing up SVN to Amazon S3

So without further a do here are the steps we’ve used to create an automated backup of SVN to Amazon S3.

1. If you haven’t already got an AWS Amazon account create one, then create a new bucket in S3.

Create a bucket in S3 for our Subversion backup files

2. Next you need to get your access credentials from the Security Credential options in the My Account menu in the AWS console.

Both Key ID and Secret Access Key will be required so that you can connect from your server to S3. Make a note of these values since we’ll need to add them to our batch file in step 4.

3. Download and install the free application S3Sync. This is the key part to the backup this smart little app will handle synchronising the SVN backup into the S3 bucket we have created.

4. Now we need to create a batch file which will perform the following steps

  • Take a hot backup of SVN
  • Copy the backup to the S3 bucket
  • Clean up the local backup on the server

Create a new folder called “C:\svn backup” inside that create a temp folder “c:\svn backup\temp” this will be location where we’ll copy our SVN backup to before moving it to S3.

Now in “C:\svn backup” create a batch file called svnbackup.bat with the contents below.

svn backup folder

set path="C:\Program Files (x86)\VisualSVN Server\bin"

svnadmin hotcopy c:\Repositories\Btb "c:\svn backup\temp\Btb"

"C:\Program Files (x86)\SprightlySoft S3 Sync\S3Sync\S3Sync.exe" -AWSAccessKeyId xxxxxx -AWSSecretAccessKey xxxxxx -SyncDirection upload -LocalFolderPath "c:\svn backup\temp" -bucketName SubversionBackup

rd "c:\svn backup\temp\Btb" /q /s

Replace xxxx with your own AWS credentials.

5. The final part to complete the process is to have the backup script run using the Task Scheduler in windows so that we get a nightly backup of the repos in SVN. Here we are going to backup the SVN repos at 6pm every day.

SVN Automated backup using Windows Task Scheduler

As in Alex’s original post the cost of using Amazon S3 for the backup is tiny, in your first year of signing up Amazon gives you 5Gb of storage for free. After that it starts at $0.125 a GB per month.

There you have it, 5 steps to help you sleep better at night with a complete SVN backup direct to Amazon S3 all for fractions of a dollar per month!