cmnoog
Last Updated: February 25, 2016
·
2.038K
· bousquet

Backup Remote SVN Repositories

We had an old svnserve instance with repositories that had mostly been abandoned since we switched to git. In preperation to shut things down, I wanted to backup those repositories locally in a way that would allow us to restore them in the rare instance it was needed. Here's a recipe that uses a combination of bash, svnsync and svnadmin to dump all revisions of each remote repository into svndump files on your local machine.

Step 1

Save the following script as svnbackup.sh:

#!/bin/sh
echo "Backing up repo: $1"
svnadmin create $1
echo "#!/bin/sh\nexit 0" >> `pwd`/$1/hooks/pre-revprop-change
chmod +x `pwd`/$1/hooks/pre-revprop-change
svnsync init file://`pwd`/$1 svn://SOURCEURL/$1 --source-username=USERNAME --source-password=PASSWORD
svnsync sync file://`pwd`/$1 --source-username=USERNAME --source-password=PASSWORD
svnadmin dump $1 > $1.svndump
echo "Cleaning up ($1)..."
rm -rf ./$1
echo "DONE"

Step 2

Make it executable:

$ chmod +x svnbackup.sh

You should now be able to run it on one repository by passing the repository name as the first argument:

$ svnbackup.sh repo1

Step 3

Setup a list of repositories to download in a file named svnrepos.txt, one repository per line:

repo1
repo2

Step 4

Use xargs to iterate over each repository in the fail, passing it into the backup script:

$ xargs -n1 < svnrepos.txt ./svnbackup.sh

Result

The result will be one <reponame>.svndump file for each repository in the list containing all revisions for that repository.