#!/bin/sh echo "please enter hostname (fqdn) of the system to restore (without spaces!)" read HOST; echo "overview of existing devices and partitions:" echo "" cat /proc/partitions echo "" cat /proc/partitions > partitions_temp grep sda1 partitions_temp || grep cciss/c0d0p1 partitions_temp if [ $? == 1 ] then echo "no partitions on system found" rm partitions_temp else echo "partitions on system found!" echo "Please delete system-partitions with fdisk (check Wiki for instructions) and rerun the restore.sh script." rm partitions_temp exit 1 fi echo "" echo "overview of existing LVM-setup:" echo "" pvscan vgscan lvscan echo "" pvscan > pv_temp grep PV pv_temp if [ $? == 1 ] then echo "no physical volumes found" rm pv_temp else echo "physical volumes found, please remove LVM-setup and rerun restore.sh" rm pv_temp exit 1 fi echo "please enter device name to restore partition-table (without spaces!). example: sda , cciss/c0d0" echo "" read DEV; DEV_FORM=`echo $DEV | sed 's/cciss\/c0d/cciss_c0d/g'` cat /proc/partitions > /mnt/backup/${HOST}/check_part grep cciss /mnt/backup/${HOST}/check_part if [ $? == 1 ] then echo "sda-device found" rm /mnt/backup/${HOST}/check_part sfdisk --force /dev/$DEV < /mnt/backup/${HOST}/dev_${DEV}_part_table else echo "cciss-device found" rm /mnt/backup/${HOST}/check_part sfdisk --force /dev/$DEV < /mnt/backup/${HOST}/dev_${DEV_FORM}_part_table fi echo "please enter the name of the partition to restore LVM (without spaces!). example: sda2 , cciss/c0d0p2 , cciss/c0d1p2 ..." echo "" read PART; echo "please enter the name of the volume-group to restore (without spaces!). example: system, data .." echo "" read PV; echo "please enter the name of the boot-device (without spaces!). example: sda1 , cciss/c0d0p1 .." echo "" read BOOT; ID=`grep -m 2 "id = " /mnt/backup/${HOST}/${PV}_vgcfgbackup.bku |tail -n 1 | cut -f2 -d'"'` echo "ID=$ID" echo "PV=$PV" echo "DEV=$DEV" echo "PART=$PART" echo "restoring PV" pvcreate --uuid $ID --restorefile /mnt/backup/${HOST}/${PV}_vgcfgbackup.bku /dev/$PART echo "restoring VG/ LV" vgcfgrestore --file /mnt/backup/${HOST}/${PV}_vgcfgbackup.bku $PV vgchange -ay lvscan echo "format all devices:" mkfs.ext3 -Lhome /dev/$PV/home mkfs.ext3 -Lroot /dev/$PV/root mkswap -Lswap /dev/$PV/swap mkfs.ext3 -Ltmp /dev/$PV/tmp mkfs.ext3 -Lusr /dev/$PV/usr mkfs.ext3 -Lvar /dev/$PV/var mkfs.ext3 -Lboot /dev/${BOOT} echo "creating root-mountpoint" echo"" mkdir /mnt/root mount /dev/$PV/root /mnt/root cd /mnt/root echo "restoring root:" tar -xzf /mnt/backup/$HOST/root.tgz if [ $? == 1 ] then echo ################################################ echo "restore of root-backup failed" echo ################################################ exit else echo ################################################ echo "root-backup restored" echo ################################################ fi echo "mounting var, usr, home, tmp, boot" mount /dev/$PV/var var mount /dev/$PV/usr usr mount /dev/$PV/home home mount /dev/$PV/tmp tmp mount /dev/${BOOT} boot echo ################################################ echo "restore var" echo ################################################ tar -xzf /mnt/backup/$HOST/var.tgz echo "var-backup restored" echo ################################################ echo "restore usr" echo ################################################ tar -xzf /mnt/backup/$HOST/usr.tgz echo "usr-backup restored" echo ################################################ echo "restore home" echo ################################################ tar -xzf /mnt/backup/$HOST/home.tgz echo "home-backup restored" echo ################################################ echo "restore boot" echo ################################################ tar -xzf /mnt/backup/$HOST/boot.tgz echo "home-backup restored" echo ################################################ echo "install mbr" echo ################################################ grub --batch < /mnt/root/etc/udev/rules.d/70-persistent-net.rules echo "70-persistent-net.rules edited" fi cd / echo "" umount /dev/$PV/var umount /dev/$PV/usr umount /dev/$PV/home umount /dev/$PV/tmp umount /dev/${BOOT} umount /dev/$PV/root echo "" fsck /dev/$PV/var fsck /dev/$PV/usr fsck /dev/$PV/home fsck /dev/$PV/tmp fsck /dev/${BOOT} fsck /dev/$PV/root echo "" echo "restore of $HOST done" mount /dev/$PV/root /mnt/root mount /dev/$PV/var var mount /dev/$PV/usr usr mount /dev/$PV/home home mount /dev/$PV/tmp tmp mount /dev/${BOOT} boot chmod 1777 tmp echo "" echo "please remove (out-commenting) all non-system /mnt/root/etc/fstab entries with vi before restart the system! example: /opt/oracle , /opt/whatever/ ..."