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.

 

 


Posted by endecotp (86.6.xx.xx) on Thu 22 Nov 2007 at 21:42
[ Send Message | View Weblogs ]
How does this compare to using an LVM snapshot?

Unless I've misunderstood something, in both cases you have the problem of distinguishing the changes made by your script and the changes made concurrently by other processes. I think it's OK if the script is limited to a single identifiable directory, but the interesting cases are things like "make install" that write all over the place.

I believe that what's needed is a way to revert all changes made by a particular process and its descendent processes. The basics needed to support this will soon be available in filesystems (e.g. btrfs), but I'm not yet sure how to use it in practice....

[ Parent | Reply to this comment ]

Posted by Federico2 (84.253.xx.xx) on Sat 24 Nov 2007 at 13:28
[ Send Message ]
RCSes like Mercurial,SVN,Git works on top on the existing file hierarchy, whereas LVM snapshot backs up the entire surface of one or more logical partitions.
Using an RCS you could still try to figure out wich process made what by doing some guesswork. Usually noone execpt your "make install" writes to /usr - unless you are running apt[itude] at the same time, but why? Still, I agree this approach could be not rock safe.
Still, an RCS could be useful if you are interested in a single directory where only one script a time is run.

[ Parent | Reply to this comment ]

Posted by Anonymous (88.122.xx.xx) on Sat 1 Dec 2007 at 19:11
> Still, an RCS could be useful if you are interested
> in a single directory where only one script a time is run.
lckdo (package moreutils) is best suited for this

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

Which init system are you using in Debian?






( 1607 votes ~ 7 comments )

 

 

Related Links