Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
Site Navigation
Linux Forums
Linux Articles
Product Showcase
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds
Free Publications


Hey Ya'll, I spent a LONG time trying to perfect a bare-metal restore of my LVM configured servers. After compiling bits and pieces from all over the net, I have found a system that at least works for me. This was tested and retested on CentOS 5.3. As always, YMMV and I'm not responsible when you fubar your system ;)

On System to Backup:



Boot from CD - System Rescue CD (available here: http://www.sysresccd.org/Download )

Press Enter to Boot

Press Enter at keymap


Type the following to pick up dhcp address
dhclient

I used a samba share to hold my backups. Yes, there are other options...
mount -t cifs -o username=admin,password=supersecretpasswd //192.168.100.100/Share /mnt/backup

Change to mounted share and create server-specific folder
cd /mnt/backup

mkdir Server1_Backup
cd Server1_Backup

Now we're going to backup the partition table.
pvscan
sfdisk -d /dev/sda > ./ptable.sda

Activate our LVM's
vgchange -ay

Now we want to copy the info on our Physical Volumes
pvdisplay > ./pvdisplay.txt

Now if we list /dev/mapper we should see our VolGroups
ls -l /dev/mapper ##to show VolGroups

Next we want to backup the LVM configuration data (this needs to be performed for each VolGroup if there ar
 more than 1)
vgcfgbackup -d -v VolGroup00 --file ./VolGroup00.lvm.backup

Now it's time to backup the boot partition, as well as the main VolGroup
partimage -d -b -z0 save /dev/sda1 ./sda1.img

partimage -d -M -b -z0 save /dev/mapper/VolGroup00-LogVol00 ./VolGroup00-LogVol00.img

## Do this for each LogVol listed
## Swap won't copy
If you're interested in the parameters, you can find them in the man pages

Now we need to backup the Master Boot Record
dd if=/dev/sda of=/mnt/nas/Wiki_DB/mbr.backup bs=512 count=1

I also like to have a copy of the following:

fdisk -l > ./fdisk.txt
cp /etc/fstab ./fstab.txt




To Restore



Boot from CD - System Rescue CD

Enter to Boot

Enter at keymap



Type the following to pick up dhcp address
dhclient



I used a samba share to hold my backups. Yes, there are other options...

mount -t cifs -o username=admin,password=supersecretpasswd //192.168.100.100/Share /mnt/backup



Change to mounted share are create server-specific folder

cd /mnt/backup
/Server1_Backup

First we'll copy back the partition table.
sfdisk /dev/sda < ./ptable.sda
## May have to use sfdisk --force if it complains

Now we have to recreate the Physical Volumes ID's
cat ./pvdisplay.txt

pvcreate --uuid SDFD7-Sdf4e-SDfas-sdf-asdf-asdf (from cat command) /dev/sda2

## If you have more than sda1 and sda2, you may have to reboot to get sda3 or more to show up in /dev

## If so, just pickup where we left off

Now we restore the LVM configs and activate the LVM's
vgcfgrestore --file ./VolGroup00.lvm.backup VolGroup00

vgchange -ay

Now it's time to restore boot and our data
partimage restmbr -e -b /dev/sda1 ./sda1.img.000

 ## Select sda1

 ## Enter in location: /mnt/backup/Server1_Backup/sda1.img.000

 ## Restore partition 
(2nd in list)
 ## Press F5

partimage -e -b restore /dev/mapper/VolGroup00-LogVol00 ./VolGroup00-LogVol00.img.000

 ## If there are multiple restore files
## cat ./VolGroup00-LogVol00.img.000 ./VolGroup00-LogVol00.img.001 | /
partimage restore /dev/mapper/VolGroup00-LogVol00

Recreate swao
mkswap /dev/mapper/VolGroup00-LogVol01

Copy over MBR
dd if=/mnt/nas/Wiki_DB/mbr.backup of=/dev/sda bs=512 count=1

Deactivate and sync volumes
vgchange -an

sync

Reboot, eject CD and enjoy frosty beer



Rate This Article: poorexcellent
 
Comments about this article

Comment title: * please do not put your response text here