How do I backup my Subversion Repository nightly? I have a network drive I'd like to dump the repo开发者_Go百科sitory to on a nightly basis.
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
精彩评论