[Novalug] Backup/partition
Paul
opensource at unixoses.com
Sat Jan 24 18:20:30 EST 2009
On Sat, January 24, 2009 9:43 am, Luther wrote:
> Hello;
> I need to know where I might find information about how to partition
> a drive to place a backup of linux in case your system might go down.!
To do a full backup, one can do a dump to a partition that is not being
used for the OS. This would need to be set up in advance, or can be
changed later with carefull manipulation. You won't be protecting against
hard drive failure, but it's nice to be able to restore the OS when
needed. If using LVM, this is a bit easier for manipulation. I guess
there is allot in question here, what FS are you using? There are many,
EXT3, LVM, ZFS.
Most are probably EXT3 or LVM, Open Solaris uses ZFS.
To backup each partition with compression:
dump -h 0 -y -f $BKUPFULLPATH$DATESTAMP"_boot.dump" /dev/$BOOTDISK
One can also do live full backups with LVM:
dump -h 0 -y -f $BKUPFULLPATH$DATESTAMP"_full.dump" $VOLGROUP$LVSNAPNAME
I do it via script in cron jobs daily:
#!/bin/bash
BKUPDISK="hdb1" #This is the 2nd hd or spare partition for the backups
to go
BOOTDISK="hda1"
MAXDISKSPACE="85"
MOUNTDIR="/mnt/"
BKUPDIR="/mnt/backup/"
BKUPDIRSEARCH="`echo $BKUPDIR | awk -F"/" '{print $3}'`"
BKUPDIRHOST="`hostname`.`uname -a | awk '{print $3}'`"
BKUPFULLPATH="$BKUPDIR$BKUPDIRHOST/"
LVSNAPNAME="lvsnap"
DATESTAMP="`date '+%F''-%R' | sed 's/://g'`"
VOLGROUP="/dev/VolGroup00/"
LV="LogVol00"
DIRNOTDELETE="backupskeep"
if [ ! -d $BKUPDIR ]
then
mkdir $BKUPDIR
if [ ! -d $BKUPDIR ]
then
echo "The dir $BKUPDIR will not create! Exitting program..."
echo
exit 0
fi
chmod 700 $BKUPDIR
fi
checkmount () {
CHECKMOUNTANDSPACE="`df -h | awk "/$BKUPDISK/ && /$BKUPDIRSEARCH/"
| awk '{print $5}' | awk -F"%" '{print $1}'`"
}
checkmount
if [ -z $CHECKMOUNTANDSPACE ]
then
mount /dev/$BKUPDISK $BKUPDIR
checkmount
if [ -z $CHECKMOUNTANDSPACE ]
then
echo "Problems mounting backup drive! Exitting program..."
echo
exit 0
fi
fi
checkmount
echo "Space is $CHECKMOUNTANDSPACE%"
echo
while [ $CHECKMOUNTANDSPACE -gt $MAXDISKSPACE ]
do
FILETODELETE="`find $BKUPDIR -type f | grep -v $DIRNOTDELETE | awk
-F"/" '{print $5}' | sort | head -1`"
rm -rf `find $BKUPDIR -name $FILETODELETE | grep -v $DIRNOTDELETE`
echo "$FILETODELETE deleted..."
sleep 1
checkmount
echo "Space is now $CHECKMOUNTANDSPACE%"
echo
done
checklv () {
LVCHECK="`lvdisplay | grep $VOLGROUP$LVSNAPNAME | awk '{print $3}'`"
}
echo
checklv
if [ -z $LVCHECK ]
then
lvcreate -L1G -s -n $LVSNAPNAME $VOLGROUP$LV
checklv
if [ -z $LVCHECK ]
then
echo "The LV is not there! Exitting program..."
echo
exit 0
fi
fi
if [ ! -d $BKUPFULLPATH ]
then
echo "backup path not there, trying to create..."
echo
mkdir $BKUPFULLPATH
if [ -d $BKUPFULLPATH ]
then
chmod 700 $BKUPFULLPATH
fi
if [ ! -d $BKUPFULLPATH ]
then
echo "backup path still not there, exitting program..."
echo
exit 0
fi
fi
dump -h 0 -y -f $BKUPFULLPATH$DATESTAMP"_boot.dump" /dev/$BOOTDISK
echo
dump -h 0 -y -f $BKUPFULLPATH$DATESTAMP"_full.dump" $VOLGROUP$LVSNAPNAME
chmod 600 $BKUPFULLPATH*
umount $BKUPDIR
lvremove -f $VOLGROUP$LVSNAPNAME
More information about the Novalug
mailing list