Subversion backup of multiple repositories via DOS .bat file

I recently had to implement Subversion at work to manage our source code. Part of that implementation was coming up with a way to automate the backup process. Since developers could be accessing code repositories at any time there is a special command (called hotcopy) in Subversion for copying a repository to another location, which you can then backup to disk, tape, etc.

I started out just doing a simple DOS .bat file to run the hotcopy. My plan was to schedule this to run in the Windows scheduler prior to the nightly backup. As I started working on the script though I found myself trying to improve it to be as generic and hands off as possible. I also wanted to backup multiple repositories.

Here are some “features” of the script:

  • It will hotcopy multiple repositories in a specified directory.
  • It can be run attended or unattended
  • It has some basic log functionality

Here is a look at the actual hotcopy command in the .bat file:
ECHO Starting SVN backup for %%G... >> %repolog% & ^
svnadmin hotcopy %repodir%%%G %repodirhot%%%G --clean-logs >> %repolog% & ^

Download it here and rename it from svn_backup.txt to svn_backup.bat.

5 thoughts on “Subversion backup of multiple repositories via DOS .bat file”

  1. Thanks, the script got me started off.

    The date naming of the log file is wrong on my computer, probably due to different local date format.

    An addition to the script could be to concider keeping the previous hotcopy while producing a new one (hot copy history). Worst case… system crashes while making hotcopy…EVIL…

  2. Thanks for the script Chris. Anders had a good suggestion about keeping the previous while making the copy. I modified the script to keep the last n backups by appending the time stamp to the hotcopy name, mapping the drive I was copying to, and using (example for deleting backups older than 8 days and mapping backup folder to R:):
    NET USE R: /delete
    SET repodirhot=%repodirhot:~0,-1%
    NET USE R: %repodirhot%
    FORFILES /P R:\ /D -8 /C “cmd /c IF @isdir==TRUE RMDIR /S /Q @path” >> %repolog% 2>&1
    NET USE R: /delete

  3. thanks a lot for the batch file! It has been extremely helpful.

    I got it backing up to an Amazon S3 bucket in no time.

  4. Thanks for the script.

    Can someone suggest how to backup to a cloud or a network folder. Also, if one could backup specific repositories instead of all the folders.

    Thanks again.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.