RSS

Subversion Backup & Restore Automation

15 Sep

BACKUP

# Subversion Repositories backup script

# Please start configuring here
svnbasedir=”/srv/svn”
svnfullbkdir=”/srv/svn/backups/full” #Don’t put a trailing slash!
logfile=”/srv/svn/backups/log.txt”
tmpdir=”/tmp”

# dont change below

#check if log file exists
touch ${logfile}
#redirect stdout and stderr to the logfile
mkdir -p $(dirname ${logfile})
exec >> ${logfile}
exec 2>&1

echo “+++ Backing up subversion repositories”
#Looks for dirs containing a file “format”, that’s not in the /db/ directory.
#This seems to match the root of a SVN repo. YMMV
repos=$(find $svnbasedir -name format -a \! -path ‘*/db/*’ -printf ‘%h\n’)

#Make sure that our backup location exists
mkdir -p ${svnfullbkdir}

for repo in $repos ; do
subpath=$(echo ${repo} | sed -e “s#${svnbasedir}/##”)
name=$(basename $subpath)
subpath=$(dirname $subpath)
echo ” $repo”
lastrev=$(svnlook youngest ${repo})

mkdir -p ${svnfullbkdir}/${subpath}
svnadmin dump -q ${repo} > ${svnfullbkdir}/${name}.dump
echo “Dumping ${repo} to ${name}.dump \n”

done

RESTORE

#!/bin/sh
# Subversion Repositories backup script

# Please start configuring here

svnbasedir=”/svn/svn”
svnfullbkdir=”/tmp/svn-dump” #Don’t put a trailing slash!
svnincbkdir=”/subversion/backup/incremental”
logfile=”/subversion/backup/log.txt”
tmpdir=”/tmp”

# dont change below

touch ${logfile}
#redirect stdout and stderr to the logfile
mkdir -p $(dirname ${logfile})
exec >> ${logfile}
exec 2>&1

echo “+++ Restoring subversion repositories ”
#Looks for subversion backup dumps taken before
repos=$(find $svnfullbkdir -name ‘*.dump’ )

mkdir -p ${svnbasedir}

for repo in $repos ; do

dirname=${repo%.dump}
name=$(basename $dirname)
$curpath = “/svn/svn/”.${name}
echo ” creating reposity ${name} at ${curpath} ”
svnadmin create /svn/svn/${name}

echo ” loading ${repo} ”
svnadmin load -q /svn/svn/${name} < ${repo}

done

***** ANOTHER WAY OF BACKUP ***********
http://www.linuxquestions.org/questions/linux-server-73/svn-server-backup-574111/

incremental backup..

# svnadmin dump –incremental /srv/svn/repos | gzip -c > /srv/svn/dumped.gz

Actual Code

#!/bin/bash

NOW=`perl -e ‘print time;’`
cd /var/backup/svn
mkdir $NOW
svnadmin dump /opt/repositories.svn/CC > $NOW/dumpfile.txt
tar cfpz $NOW.tgz $NOW
rm -rf $NOW

…then follow that up with another cronjob that does this:

CRON JOB

45 3 * * * for i in `find /var/backup -type f -mtime +2` ; do rm -f $i ; done

The first cronjob does a full dump of the svn database and then zips it. (We are paranoid, we only do full dumps of databases and database-like applications.) Later on after that’s complete, the nightly backup process runs and the full dump is taken as part of a daily backup to tape. The second cronjob deletes anything it finds in the /var/backup tree that’s older than two days. That way I know I have two days of backups on disk, and I can restore the full database from any day I have tape for.

How to Add a script to Cron Job.
——————————–

Advertisements
 
Leave a comment

Posted by on September 15, 2009 in subversion

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: