If you have one or several subversion repositories stored under the same folder, this script will help you to automatically back them up.
This script does a full dump for each repository if no previous dump was found or if the supplied parameter is “Base” or “Full”.
If neither is true, it does an incremental dump using a range of revisions going from the last revision of the full dump to the youngest found in the repository.
Warning: I have not tested a restore, please verify by yourself that this works :
#!/bin/bash
# paths to the svn root and where backups get dumped
svnroot=/var/lib/svn
dumptarget=/var/dumps/svn
# if you don't have multiple repos, set this to true
single_repo=false
if [ -n "$1" ]; then
level=$1
[ "$level" == "Base" ] && level=Full
else
echo "Error : No Job level specified" >&2
echo "Usage: `basename $0` [Base|Full|Incremental|Differential|Since]"
exit 1
fi
# (more) secure umask
umask 0027
backup_repo() {
dir=$1
repo=$2
# find out last revision for repository
youngest=`svnlook youngest $dir`
# Full dump, save last revision for next incrementals
if [ ! -f "$dumptarget/$repo.full.gz" ] || [ "$level" == "Full" ]; then
echo "Full dump of $repo (rev. $youngest)"
svnadmin dump -q "$dir" | gzip > "$dumptarget/$repo.full.gz"
echo $youngest > "$dumptarget/$repo.last"
rm -f "$dumptarget/$repo.inc.gz"
# Inremental backup if last revision in full dump found
elif [ -f $dumptarget/$repo.last ]; then
previous=`cat $dumptarget/$repo.last`
oldest=$(($previous + 1))
if [ ! "$previous" == "$youngest" ]; then
echo "Incremental dump of $repo (rev. ${oldest}-${youngest})"
svnadmin dump -q --revision $oldest:$youngest --incremental "$dir" | gzip > "$dumptarget/$repo.inc.gz"
else
echo "No changes in $repo (rev. ${youngest})"
return 1
fi
else
echo "Error : did not find last dumped revision ($repo.last file)" >&2
exit 1
fi
}
if $single_repo; then
backup_repo "$svnroot" "repository"
else
for d in `find $svnroot -mindepth 1 -maxdepth 1 -type d`; do
backup_repo "$d" "`basename $d`"
done
fi
exit 0
Include this in the Job ressource in bacula-dir.conf: (the job level is substituted for %l when bacula calls the script)
RunScript {
Runs on Client = Yes
Runs When = Before
Abort Job on Error = No
Command = "/path/to/script/dump_svn %l"
}
For more infos : http://svnbook.red-bean.com/nightly/en/svn.reposadmin.maint.html#svn.reposadmin.maint.migrate