How do I backup my Subversion Repository nightly? I have a network drive I'd like to dump the repository to on a nightly basis.
If the server fails, you may be able to access a recent version of your files, but without the repository all your history is lost forever. The simplest (but not recommended) way is just to copy the repository folder onto the backup medium. However, you have to be absolutely sure that no process is accessing the data.
When you commit changes to your repository, they will be stored on server S inside your subversion repository. The repository is actually constructed of a series of deltas stored inside the db/revs folder - changes from one version of the repository to the next.
svnadmin is the administrative tool for monitoring and repairing your Subversion repository. For detailed information on repository administration, see the maintenance section for the section called “svnadmin”.
Check out the Repository Maintenance chapter in The Book on how to pull a dump out of the repository. Then use a timed service (at
or cron
for example, or the very nice task scheduler in Windows OS's, depends on your server's system) to execute the dump nightly. Done.
The SVN book has a section on Repository Backup.
The svnadmin hotcopy
command allows you to safely backup a live repository.
The svnsync
command is another possibility.
I just wrote a short script to do the job. The first run does a full backup, every further run does just an increment over the last commits during last backup. the backup files will get the number of the last revision to track the procedure.
Set up the right settings for
WORKDIR=path to where this script resists
SVN_REPO_LOCATION=path to where the repository resists on hd
BACKUPDIR=path to where the backup should goes to
SVN_LOACTION=root location which you use in your svn command
and add the script to cronjob, thats it.
#!/bin/bash
WORKDIR=/home/user/svnbackup
SVN_REPO_LOCATION=/opt/svn
BACKUPDIR=./backup
SVN_LOACTION=https://mysvn.server.com/svn
cd $WORKDIR;
CURRENT_VERSION=`svn info $SVN_LOACTION | grep Revision | awk '{print $2}'`
LAST_VERSION=`cat svn.version 2>/dev/null`
mkdir -p $BACKUPDIR;
if [ "$LAST_VERSION" = "" ]
then
echo fullbackup;
svnadmin dump -q $SVN_REPO_LOCATION > $BACKUPDIR/svn_backup_$CURRENT_VERSION.dump;
echo $CURRENT_VERSION > svn.version;
else
if [ "$LAST_VERSION" == "$CURRENT_VERSION" ]
then
echo backup not necessary;
else
echo incremental;
svnadmin dump -q $SVN_REPO_LOCATION -r$LAST_VERSION:$CURRENT_VERSION --incremental > $BACKUPDIR/svn_backup_$CURRENT_VERSION.dump;
echo $CURRENT_VERSION > svn.version;
fi
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With