[CentOS] best practice backup

Thu May 3 16:06:21 UTC 2007
Paul <unix at bikesn4x4s.com>

On Thu, May 3, 2007 8:14 am, D. Karapiperis wrote:
> Hi there,
>
> I am using tar to backup the whole system (specific directorues
> usr,lib,sbin,etc,var,home,root).
> On bare metal recovery I install the minimal portion of the syetm and then
> I throw the tarballs.
>
> Any opinions?

I'm a fan of full system backups,  cause it requires minimal thought
process and will cover for most types of failures.  If your using LVM and
have a second hard drive, here is a script I made that's been tested to
full recovery.  Can do many variations of it.  Can even back up to an nfs
share, ftp/sftp it to a remote location, etc.

I automate daily full backups, completely hands off maintainance free.  :)

script:
----------<snip>
#!/bin/sh
BKUPDISK="hdb1"   #This is the 2nd hd for the backups to go
MAXDISKSPACE="75"       # This is the variable of max acceptable disk
usage in whole percent value
mkdir /mnt/bkupfull
chmod 700 /mnt/bkupfull
mkdir /mnt/"$BKUPDISK"
chmod 700 /mnt/"$BKUPDISK"
lvcreate -L1G -s -n fullbkup /dev/VolGroup00/LogVol00
mount /dev/VolGroup00/fullbkup /mnt/bkupfull
mount /dev/"$BKUPDISK" /mnt/"$BKUPDISK"
DISKFULL="`df -h /dev/"$BKUPDISK" | tail -1 | awk '{print $5}' | awk -F
"%" '{print $1}'`" # The disk space of backup disk

# Keep deleting oldest 2 backups until backup disk disk space is under
specified used space
while [ $DISKFULL -gt $MAXDISKSPACE ]
do
        rm -rf `ls -t /mnt/"$BKUPDISK"/*.dump | tail -2`
        DISKFULL="`df -h /dev/"$BKUPDISK" | tail -1 | awk '{print $5}' |
awk -F "%" '{print $1}'`"
done

dump -h 0 -y -f /mnt/"$BKUPDISK"/`date '+%F''-%R'`_boot.dump /dev/hda1
dump -h 0 -y -f /mnt/"$BKUPDISK"/`date '+%F''-%R'`_full.dump
/dev/VolGroup00/fullbkup
chmod 600 /mnt/"$BKUPDISK"/*
umount /mnt/"$BKUPDISK"
umount /mnt/bkupfull
lvremove -f /dev/VolGroup00/fullbkup
------</snip>

SOP:
-----<snip>
FULL BACKUP:

lvcreate -L4G -s -n fullbkup /dev/VolGroup00/LogVol00

mount /dev/VolGroup00/fullbkup /mnt/bkupfull

mount /dev/hdb1 /mnt/hdb1

dump -h 0 -f /mnt/hdb1/fullbkup.dump /dev/VolGroup00/fullbkup

dump -h 0 -f /mnt/hdb1/boot.dump /dev/hda1


umount /mnt/hdb1

umount /mnt/bkupfull

lvremove /dev/VolGroup00/fullbkup

-------------

RESTORING

fdisk /dev/hda

# fdisk -l

Disk /dev/hda: 20.5 GB, 20576747520 bytes
255 heads, 63 sectors/track, 2501 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        1300    10337827+  8e  Linux LVM
/dev/hda3            1301        2501     9647032+  83  Linux


mkfs -t ext3 /dev/hda1

mkfs -t ext3 /dev/hda3

pvcreate /dev/hda2

vgcreate VolGroup00 /dev/hda2

vgscan

vgchange -ay

lvcreate -L8G -n LogVol00 VolGroup00

lvcreate -L1.75G -n LogVol01 VolGroup00

lvresize -L +108M /dev/VolGroup00/LogVol00

mkswap /dev/VolGroup00/LogVol01

mkfs -t ext3 /dev/VolGroup00/LogVol00

restore -rf /mnt/hda3/boot.dump

restore -rf /mnt/hda3/bkupfull.dump

rm restoresymtable

e2label /dev/hda1 /boot

------

Tyep "grub"
root (hd0,0)
setup (hd0)
quit
reboot

------</snip>