Iterate Through Directories and Backup SVN Repositories

I found this useful as I have quite a few SVN repositories that I’m responsible for maintaining. Due to the large number I didn’t want to manually specify each directory in an array as that involved more upkeep that I really wanted to have on my plate. This script will go through a target parent directory and perform an svnadmin dump on each repository to a gzipped file in the target backup directory. So for example if all of your svn repositories reside in /srv/svn and you want your gzip files to end up in /home/backup then create a shell script from the below info and set SVN_PARENT=/srv/svn and SVN_BACKUP=/home/backup. Right now I only care about keeping a day of backups so this script deletes all of the backup files prior to performing the next round of backups. Delete that line if you’re looking to keep a larger backup history.

#/bin/bash

SVN_PARENT=
SVN_BACKUP=
DATE=`date '+%F'`
TEMPFILE=/tmp/svn_backup.tmp

touch $TEMPFILE
ls $SVN_PARENT >> $TEMPFILE
DIR_LIST=( `cat "$TEMPFILE" `)

rm -rf $SVN_BACKUP/*.gz

for i in "${DIR_LIST[@]}"
do
        svnadmin dump $SVN_PARENT/$i | gzip > $SVN_BACKUP/$i.$DATE.svn.gz
done

rm -rf $TEMPFILE

Copyright © All Rights Reserved · Green Hope Theme by Sivan & schiy · Proudly powered by WordPress