Killed /home during install of another distro
Karl Auer
kauer at biplane.com.au
Mon Jul 30 00:20:25 UTC 2007
On Mon, 2007-07-30 at 02:19 +0300, Dotan Cohen wrote:
> no way to boot and google the situation, I played Y, Y, Y to all
> fsck's questions. Now, /home is empty. I do have a backup from 4 weeks
> ago, as I backup the first of every month, but I have done quite a bit
> of work this past month. I'm very interested in recovering the data.
You could try looking in /lost+found.
And start backing up every day. It's easy enough to attach a cheap USB
drive and set up a cron job to just rsync /home to it every night. A
simple script will cycle the target directories, and you can have a
week's worth or even a month's worth on that disk, at very little cost
in disk space due to the magic of rsync and hard links.
Modify these scripts appropriately for your needs (especially paths,
DEST, SOURCES etc), put them into $DEST, and tell cron to run the "rb"
script as often as you like. Note that the first run will take a while,
as it has to copy everything. Subsequent runs will be MUCH faster, as
only altered files will be copied, unaltered files will be hard-linked
to.
These scripts assume a local copy, by the way. You could back up to a
remote site pretty easily, but you need to set up a transport (like ssh)
and I'm not sure if the hard-link idea would still work.
Regards, K.
~~~~~~~~~~~~~~~~~ start of backup script ~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/sh
#
# Rotates backups, does a new one.
#
DEST=/media/usbdisk/bu
cd $DEST
if ./r && ./b ; then
exit 0 ;
else
exit 1
fi
~~~~~~~~~~~~~~~~~ start of rotater script ~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/sh
#
# This script rotates a set of backup directories.
#
DEST=/media/usbdisk/bu
# List the backup directories here, in order oldest to youngest.
# These should generally be fully qualified paths.
DIRS="$DEST/backup.07 "
DIRS="$DIRS $DEST/backup.06"
DIRS="$DIRS $DEST/backup.05"
DIRS="$DIRS $DEST/backup.04"
DIRS="$DIRS $DEST/backup.03"
DIRS="$DIRS $DEST/backup.02"
DIRS="$DIRS $DEST/backup.01"
DIRS="$DIRS $DEST/backup.00"
# This function rotates the backup directories. After this function has
# been called, $NEXT contains the name of the directory that should
# receive the new backup, $CURRENT contains the name of the youngest
# backup.
rotate_dirs()
{
# check that all candidates are directories.
for i in $DIRS ; do
{
if [ ! -d $i ] ; then
echo "$i is not a directory!" > /dev/stderr
exit 1
fi
}
done
# move them all "down"
unset $NEXT
for i in $DIRS ; do
{
if [ -z $NEXT ] ; then
NEXT=$i
echo remove oldest directory $i
rm -fr $i
if [ -e $i ] ; then
echo "Can't remove oldest directory!"
exit 1
fi
else
echo rename $i to $NEXT
mv $i $NEXT
if [ -e $i ] ; then
echo "Can't rename $i to $NEXT!" > /dev/stderr
exit 1
fi
CURRENT=$NEXT
NEXT=$i
fi
}
done
}
# Move all the backup directories up one, oldest will be lost.
rotate_dirs
# create $NEXT for this backup
mkdir $NEXT
if [ ! -e $NEXT ] ; then
echo "Can't create new directory $NEXT!" > /dev/stderr
exit 1
fi
if [ ! -d $NEXT ] ; then
echo "$NEXT is not a directory!" > /dev/stderr
exit 1
fi
exit 0
~~~~~~~~~~~~~~~~~ start of rsync script ~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/sh
#
# this script backs up all the directories given in SOURCES to DESTINATION,
# hardlinking to the most recent PREVIOUS version.
#
# Note that source directories should be specified with NO trailing slash,
# otherwise their contents will end up in the backup directory directly.
#
SOURCES=""
SOURCES="$SOURCES /home"
SOURCES="$SOURCES /etc/apache2"
SOURCES="$SOURCES /etc/bind"
SOURCES="$SOURCES /usr/share/moin"
SOURCES="$SOURCES /var/www"
DESTINATION=/media/usbdisk/bu/backup.00
PREVIOUS=/media/usbdisk/bu/backup.01
for source in $SOURCES ; do
{
rsync -av --delete --link-dest=$PREVIOUS $source $DESTINATION
}
done
exit 0
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au) +61-2-64957160 (h)
http://www.biplane.com.au/~kauer/ +61-428-957160 (mob)
More information about the ubuntu-users
mailing list