Creating simple transactions for shell scripts with mercurial
Posted by loic on Thu 22 Nov 2007 at 09:44
I've recently started to use mercurial to add a crude form of transactions to a set of shell scripts I wrote to automate some system administration tasks (installing mediawiki, tiddlywiki, fudforum, mailman, postfix satellite ...).
It goes like this:
cd / hg init hg add hg commit -m "slurp" # not for the faint of heart if script ; then hg commit -m "script" ; else hg revert --all ; fi
The details are a little different as shown in this page.
There is a debian package via the following repository:
deb http://ouzo.flouzo.net/ouzo ./
The ouzo package is a bag of scripts, only interesting in this context because it demonstrates how I use transactions.
This hack works best on small chroot and vservers (typically under 1GB), otherwise mercurial is likely to use too much horsepower. I would not advise anyone to try it unless (s)he knows exactly what (s)he is doing.
For instance, the lack of owner/group support by mercurial is likely to create problems when rolling back a MySQL database.
Details on how to usefully insert a chroot into mercurial can be found by reading the following shell script.
In conclusion. I've found easier to cope with mercurial limitations (lack of uid restoration for instance) when something goes wrong, rather than being left with an aborted shell script and random files partially removed/added/modified.