1

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 Answers2

2

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.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • Thanks Ry4an, We are doing a file system backup. The problem with file system back up is that the recovery takes a lot of time. – Rajeev Saraswat Feb 19 '15 at 20:08
  • 1
    Yeah, you should use clone/push. I know you said you've tried it in the past, but it's really the way to go. What didn't work for you? – Ry4an Brase Feb 19 '15 at 20:45
  • It takes a lot of time to back up 500 plus repositories by using the clone/push. Is there a way, we can run the clone/push for these repositories in parallel and not sequentially. – Rajeev Saraswat Feb 19 '15 at 22:11
  • @RajeevSaraswat What's the problem? Just start the "hg push" commands in parallel rather than sequentially. There's no limitation within Mercurial that prevents you from doing that, it's just a matter of your backup script/tool. – vog Nov 21 '18 at 12:09
0

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.

Christophe Muller
  • 4,850
  • 1
  • 23
  • 31