Is it possible to backup a filesystem with many Mercurial repositories (e.g., with rsync on the filesystem) and have the backup in an inconsistent state?
The repositories are served by ssh and serves this set of requests: {push, pull, in, out, clone}. It does not have ‘hg commit’ applied to it directly (which has a known race condition).
Mark Drago is correct that Mercurial writes its own files in a careful order to maintain integrity. However, this is only integrity with regard to other Mercurial clients. The locking design in Mercurial allows one Mercurial process to create a new commit by writing files in this order:
while other Mercurial processes will read the files in this order
The reader will thus not see a reference to the new filelog data since the changelog is updated last in an atomic operation (a rename, which POSIX requires to be atomic).
A backup program will not know the correct order to read the Mercurial files and so it might read a filelog before it was updated by Mercurial and then read a manifest after it was updated:
rsyncreads.hg/store/data/foo.ihgwrites.hg/store/data/foo.ihgwrites.hg/store/00manifest.ihgwrites.hg/store/00changelog.irsyncreads.hg/store/00manifest.irsyncreads.hg/store/00changelog.iThe result is a backup with a changelog that points to a manifest that points to a filelog revision that does not exist — a corrupt repository. Running
hg verifyon such a repository will detect this situation:This tells you that the manifest of revision 1 refers to revision
f57bae649f6eof the filefoo, which cannot be found. It is possible to repair this situation by making a clone that excludes the bad revision 1:So, all in all, it is not that bad if you use a general backup program to backup your Mercurial repositories. Just be aware that you might have to repair a broken repository after you restore it from backup. The changeset you lose will most likely still be on the developer’s machine and he can push it again after you repair the restored repository. The Mercurial wiki has more information on repairing repository corruption.
The completely safe way to backup a repository is of course to use
hg clone, but it might not be practical to integrate this with a general backup strategy.