On Thu, Apr 04, 2002 at 07:49:15AM +0200, Rob van der Heij wrote:
> I'm about to program changes to critical files. How does
> one do that in a reliable way?
>
> On CMS one would do it like this:
<snip>
> How do you do this with Linux. ...
Here's some cute items for Unix in general:
____________[ cutover ]_____________________________________________________
#!/bin/sh
for F in $*
do
if [ -r $F+ ]
then
[ -r $F--- ] && rm -rf $F---
[ -r $F-- ] && mv $F-- $F---
[ -r $F- ] && mv $F- $F--
[ -r $F ] && mv $F $F-
mv $F+ $F
sync ; sync
echo "Cutover of $F complete."
else
echo "No cutover for $F since no new version present."
fi
done
exit 0
__EOF_______________________________________________________________________
and:
____________[ fallback ]____________________________________________________
#!/bin/sh
for F in $*
do
if [ -r $F ]
then
mv $F $F+
[ -r $F- ] && mv $F- $F
[ -r $F-- ] && mv $F-- $F-
[ -r $F--- ] && mv $F--- $F--
sync ; sync
echo "FallBack of $F complete."
else
echo "No fallback for $F: no current version present."
fi
done
exit 0
__EOF_______________________________________________________________________
I wrote these 12+ years ago since I couldn't update a running
executable, so this allowed me to engage a new file for any
subsequent operations. It's also usable w/ directories, too.
The trick is to create the new file as file+ and then just
cutover file
which will "rotate" it into the barrel. To avoid complications
with running executables the backups are maintained.
This doesn't eliminate timing windows when a file is "missing"
for the short period, but it sure narrows it down (and cuts
down on how much typing I have to do, always a reassuring
factor given my ability to inject typos).
And, because I'm a paranoid, I maintain up to three backup
copies of the file (or directory) which can be restored just
as quickly using the fallback mechanism.
--
John R. Campbell Speaker to Machines [EMAIL PROTECTED]
- As a SysAdmin, yes, I CAN read your e-mail, but I DON'T get that bored!
Disclaimer: All opinions expressed above are those of John R. Campbell
alone and are seriously unlikely to reflect the opinions of
his employer(s) or lackeys thereof. Anyone who says
differently is itching for a fight!