A Simple Daily Backup Strategy for Subversion Using 7-zip and Dropbox

by James Richards February 17, 2009


I’m using Subversion (via VisualSVN Server) for source control. I recently decided to add daily offsite backup to my setup. This was relatively easy to accomplish with 7-zip, Dropbox, and a batch file.

VisualSVN Server is a free package that makes setting up and managing Subversion on Windows really easy. It includes Subversion, an Apache web server, and a GUI management console.

Dropbox is an easy to use online file storage and synchronization service. It’s free for accounts up to 2GB.

7-zip is a free, open source zip library that can be controlled from the command line. [more]


First I signed up for a Dropbox account, and downloaded and installed their synchronization software. After setup, I opted to move the “My Dropbox” folder to C:\Dropbox so it wouldn’t be located in my user profile directory. This was easy to do – I just selected Preferences… from the Dropbox system tray icon, clicked the Move… button, and specified the new directory.

Next I downloaded and installed 7-zip. Pretty self explanatory.

After all the components were installed, I made sure that the locations of the svnadmin and 7-zip utilities were added to the PATH environment variable. Right-click on My Computer, and choose Properties… Then click the Advanced tab and the Environment Variables button. Under the System Variables list, scroll to find the Path variable, select it and click Edit. On my system, I added the follow two entries to the end of the Path variable: “C:\Program Files\VisualSVN Server\bin\;C:\Program Files\7-Zip\;” (no quotes). When finished click OK 3 times.

Batch File

Now that all the pieces are in place, here’s a simple batch file that exports a repository to a temporary folder, zips it up, copies the zip file to the Dropbox folder and cleans up after itself. The script is called svnbackup.bat and takes a single argument, which is the name of the Repository to backup.

mkdir C:\Temp\%1
svnadmin hotcopy D:\Repositories\%1 D:\Temp\%1
7z a C:\Temp\%1.zip D:\Temp\%1*
copy C:\Temp\%1.zip "C:\Dropbox\My Dropbox\Repositories\%1.zip"
del C:\Temp\%1.zip
attrib -r C:\Temp\%1\format
attrib -r C:\Temp\%1\db\format
del /q /s C:\Temp\%1\*.*
rd /q /s C:\Temp\%1

Once the zip file is dropped in the Dropbox folder, synchronization automatically kicks in and the zip file is backup up to the Dropbox servers.


A couple of things to note. On my system, Subversion is set up to keep all repositories in the D:\Repositories directory. Also, I realize I could have made a variable for the temp directory, but I was being lazy. Finally, when deleting the temporary directory, I was trying to figure out how to tell attrib to recursively walk the subdirectories to clear all of the read only flags, but I couldn’t get it to work. Since there were only two read only files in the tree, I opted to punt and make two calls.


The final step to this solution is to automate the backup of all repositories on a daily basis. I created a second script which calls the svnbackup script with the name of each repository. It’s called svnbackup_all.bat, and here’s an example of what would go in there.

call C:\Scripts\svnbackup MyRepository
call C:\Scripts\svnbackup My2ndRepository

Once this script was in place I added a Scheduled Task to run it every night – while I’m sleeping more soundly with the knowledge that my source code will not be lost in the event of a major disaster.


VisualSVN Server
Chad Myers DevEx article on Repeatability which includes a nice overview of VisualSVN Server
Google Search: 7-zip command line

Tags: , , , ,

7-zip | Dropbox | How To | VisualSVN

Powered by BlogEngine.NET
Theme by Mads Kristensen | Modified by Mooglegiant
Creative Commons License This work is licensed under a Creative Commons Attribution 3.0 United States License.


James Richards

Hi, I'm James Richards the CTO and co-founder of Artisan Global LLC. We make location-aware mobile apps with maps. I'm the author of QuakeFeed and I helped launch Zaarly at LASW Feb 2011. I also enjoy surfing, snowboarding, golfing, yoga, and music. I love my family: Linda, Sequoya and our cats Remy and Twiggy. Thanks for stopping by, I hope you find something helpful here.

Subscribe by RSS   Follow me on Twitter   Connect on Facebook   View my profile on LinkedIn

Amazon Associates

Some of my posts may contain Amazon Associates links. I only include these links when it makes sense within the context of the article. If you are in the market for one of these items, please consider clicking on an affiliate link to make your purchase. You still get the same great deal from Amazon and it will help me pay for hosting and bandwidth. Thanks!