Backup Multiple Mercurial Repositories on a server

There are several methods, as usual, to backup.  This is what I choose in order to safely backup mercurial repositories.  Basically create the script and add to cron.  If this fails with a "not trusted" statement you need to add the user and group you are using for backup in your /etc/mercurial/hgrc.d/mercurial.rc file as follows:

[trusted]
users = backup
group = backup

The backup script is below:

#! /bin/bash

########################################################################
# Change these to fit your environments
########################################################################
REPOS_BASE="/srv/mercurial/repos"
BACKUP_DIR="/srv/backup/mercurial/repositories"
BACKUP_CMD="hg bundle -a"
#
########################################################################

########################################################################
for repository in $REPOS_BASE/*
do
reposBase=`basename $repository`
if [ ! -d $BACKUP_DIR/$reposBase ]; then
mkdir -p $BACKUP_DIR/$reposBase
fi
cd $REPOS_BASE/$reposBase
$BACKUP_CMD $BACKUP_DIR/$reposBase/$reposBase.hg
cp $REPOS_BASE/$reposBase/.hg/hgrc $BACKUP_DIR/$reposBase/
done

If you need to do a restore simply do the following:

# hg init /srv/mercurial/repos/reponame
# cd /srv/mercurial/repos/reponame
# hg unbundle /srv/backup/mercurial/repositories/reponame/reponame.hg
# cp /srv/backup/mercurial/repositories/reponame/hgrc /srv/mercurial/repos/reponame/.hg/
# chown -R wwwrun:www /srv/mercurial/repos/reponame

One thought on “Backup Multiple Mercurial Repositories on a server

  1. Pingback: links for 2010-04-08 « Object neo = neo Object

Leave a Reply