My Subversion Backup Script

In the name of all that’s good – backup your Subversion repository!

Your repo is the history of the code that runs your business.  Make sure you back that beast up.  You can safely back it up while developers are using it by running the dump command.

Take a dump

I like to script my dumps (backups) with a Windows batch script and then compress the output for long term storage. Here’s my batch script:


cd e:

set ts=%date:~10,4%%date:~4,2%%date:~7,2%
ECHO %ts%
set repoPath=E:\Repositories\Development
set tempPath=C:\SvnBackupStagingArea\DevRepoDump%ts%.svn
set backupPath=\\networkShareForBackup\DevRepoDump%ts%.svn.7z

ECHO Dumping SVN Repo 
svnadmin dump %repoPath% > %tempPath%

ECHO Zipping
cd "c:\Program Files\7-Zip"

set tempPathZip=%tempPath%.7z

7z a %tempPathZip% %tempPath%

ECHO Moving to network share
move %tempPathZip% %backupPath%

ECHO Cleaning up
del %tempPath%

ECHO Done.
ECHO Presented for you in it's smallest form, your backup: 
ECHO %backupPath%

The script creates a nice timestamp (ts) to append to the backup filename – it’ll end up to be something like DevRepoDemp20131111.svn.7z when it’s done. This depends on how your dates are set up in Windows so you might need to change this or remove it.

It then sets the temporary staging path and the final zipped up dump path for where you want the result to end up. The server that has the repository should be where you stage the backup file, so it can backup and zip as fast as possible. Make sure you have at least 1.5 times more free space available than the size of the repository – it’ll need to create a dump and then zip that dump.

SVNADMIN DUMP creates a hot copy of the repository. This works even if developers are using the repo while you are backing it up – Those particular changes probably won’t be in this backup though. That’s why you should run this on a schedule, preferably at least once a day that people are not using the repo, like around lunch time :)

Note: If you are using TortoiseSVN, make sure you have also installed the command line tools with it. Check your machine for svnadmin.exe – if you do not have it, re-install TortoiseSVN and include the tools.

7-Zip will compress the backup copy. And yes, this makes a big difference in the resulting file size. Our repo was 10 gig and it zipped down to 3.5g.

It’ll then move the zip to a network share, deleting the temp file.

Download the zipped batch file

Let me know if this helped you out.


Leave a Reply