Skip to content

Instantly share code, notes, and snippets.

@kulp
Created May 16, 2009 21:42
Show Gist options
  • Save kulp/112814 to your computer and use it in GitHub Desktop.
Save kulp/112814 to your computer and use it in GitHub Desktop.
Back up Subversion repositories incrementally (easily run from cron).
#!/bin/bash
# Back up Subversion repositories. Run from cron.
# Somewhat ironic that I post this to github ...
svndir=$HOME/svn
destdir=$HOME/svnbackups
dumpcmd="svnadmin dump --quiet --incremental"
repos=`find "$svndir" -maxdepth 1 -mindepth 1 -type d -exec basename {} \;`
for repo in $repos; do
oldend=`ls -1t $destdir/$repo.*.*.* 2>/dev/null | head -n1 | cut -d. -f 3`
head=`svn info "file:///$svndir/$repo" | grep ^Revision | cut -d' ' -f 2`
start=$(( ${oldend:-0} + 1 ))
# Skip this repository if there are no new revisions since last backup
if [ $start -ge $head ]; then continue; fi
echo "Backing up repo $repo revisions $start - $head ..."
# Set up temporaries
tempdir=`mktemp -d "$repo.$start.$head.XXXXXX"` || exit 1
temptar=`mktemp "$repo.$start.$head.XXXXXX"` || exit 1
destfile="$repo.$start.$head.`date -Iseconds`.svndump"
# Do the backup
cp "$svndir/$repo.access" "$svndir/$repo.passwd" $tempdir/ &&
$dumpcmd -r$start:$head "$svndir/$repo" > "$tempdir/$destfile" &&
tar -C $tempdir -zcf $temptar . &&
mv $temptar "$destdir/$repo.$start.$head.tar.gz" &&
rm -rf $tempdir &&
echo "... done" || echo '... failed!'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment