Hg ( Merculrial ) Backup policy

174 Views Asked by At

We have 500 plus Hg repositories and am looking for a quick and efficient want of backup. Is there a script or Tool that we can use to backup these repositories. We tried Hg bundle, hg clone and regular file system backup but they are not helping.

Is there a standard practice, or some documentation for Hg repositories backup policy?

A follow-up question, what will happen when a user is in a middle of pushing the changeset and we start the backup ?

We do use RhodeCode to publish the Hg repositories. Thanks

2

There are 2 best solutions below

4
Ry4an Brase On

There's no standard. A true FS-level snapshot taken during a push will be fine, but a non-instantaneous mirroring operation (recursive copy) could end up with a corrupt repo, though it would be repairable to the pre-push state.

In the past I've done something as simple as:

for repo in $(find /srv/repos -type d -name .hg | sed 's/\.hg$//') ; do
    hg --cwd $repo --repository $repo push ssh://backupserver/$(basename $repo)
done

That pushes all repos to a remote ssh server, incrementally, with full updating-while-pushing integrity, creating them if necessary.

0
Christophe Muller On

I have a somewhat similar solution of cloning/pulling from a backup server but I trigger the backup on an hg hook.

In the main server global hgrc, I have:

changegroup.backup = .../backup.sh

and in backup.sh something like:

REPO=`hg root`
ts sshpass -p '...' ssh hg@backupserver "~/bin/pull.exp $REPO" 2>> $LOG

Ts (task spooler) allows the operation to happen asynchronously. The expect script is handling the fact that the repository might be new (thus performing an hg clone --noupdate) or already existing (thus performing an hg pull) and also can give the ssh key a passphrase when requested.

Pushing on the second server is only allowed for the backup hook, so no issue of multiple heads or needed force can happen.

What I find interesting in this type of real time backup is that in case of crash of the main server, it should be much faster to switch to the backup one.