Subversion (SVN): How do you set up backup for your Subversion repositories?
Subversion is becoming more and more popular every day. To get quick installation guide, see my post on installing Subversion. Once you have Subversion set up, make sure you have backups of repository setup! This is one of those things most people forget to do. If you followed the installation guide and did source install, you already have a tool available to you. You can find hot-backup.py tool in the tools/backup/ directory of the Subversion source distribution. One thing about this script is that it doesn’t backup all your repositories. Which might be an issue if you create more repositories but forget to create a script to backup that particular repository. Here is a very simple shell script to help you backup all of your subversion repositories. You can edit it to point to different /svn location if you didn’t install to default location. Make sure you copy hot-backup.py to a location which is included in your path so your scripts will work.
mkdir /backups/repos -p
for repostobackup in `ls /svn/` ; do
filename=`basename ${repostobackup}`
if [ ! $filename = "" ]; then
hot-backup.py –archive-type=bz2 /svn/${filename} /backups/repos
fi
done
This will create your backup files and compress them using bzip2. You can also use zip or gz if you prefer. Another thing you should do is to edit the hot-backup.py script and change num_backups to be whatever you think is a good number. I personally use: num_backups = 10
That’s all there is to it. Just add this script to your crons and your backups will be automated. You may want to consider moving your backups to another server by adding ftp, scp or rsync at the end of the script.

(2 votes, average: 4.5 out of 5)

How do you restore the backup repository?
You would unzip the appropriate directory. It will unzip into same structure as your current repository.
Hi,
I tried to run the backup script and getting the following error ‘No such file or directory’. Can you please tell me what is wrong with the script? I have the hot-backup.py in the path.
Output for :./svn_backup.sh
demo1 demo2
: No such file or directory
Script (svn_backup.sh):
mkdir /backups/repos -p
for repostobackup in ‘ls /svn/’ ; do
filename=basename ${repostobackup}
hot-backup.py –archive-type=bz2 /svn/${filename} /backups/repos
done
I am getting same error ‘No such file or directory’ when directly run the hot-backup.py.
Do I need to make any changes to the hot-backup.py? Or anything wrong with script?
Do you have your repository installed under /svn/ ?
Yes. I have two demo1 and demo2 which has all the following sub folders:
/svn/demo1
/svn/demo2
When run the following script I get the following output:
demo1 demo2
: No such file or directory
Here is Script:
mkdir /backups/repos -p
for repostobackup in ‘ls /svn/’ ; do
filename=basename ${repostobackup}
hot-backup.py –archive-type=bz2 /svn/${filename} /backups/repos
done
Folks:
I am backing up My SVN Repo through SAMBA Share and using my Tape Driver which is connected to my windows.
I never checked the “Reliability ” of backup still.
Is that will work ..
—-
Britto
As long as you can recover from your backup, I don’t see why it wouldn’t work. You should still test the recovery process to make sure if needed, you can recover from disaster.
Thanks a lot.I am testing it now.