Recovering data from backups

Ok, there's been a disaster. don't panic.

Preparing the logical volume for recovery

Plug in your most recent backup media, and update LVM's knowledge of the system volumes:

jupiter:~# vgscan
  Reading all physical volumes.  This may take a while...
  Found exported volume group "vgbackup0_jupiter" using metadata type lvm2
  Found volume group "vghome_jupiter" using metadata type lvm2
  Found volume group "vg0_jupiter" using metadata type lvm2
jupiter:~# vgs vgbackup0_jupiter
  VG                #PV #LV #SN Attr  VSize   VFree  
  vgbackup0_jupiter   1   1   0 wzx-n 372.61G 279.46G
jupiter:~# 

The x in the Attr column means we need to vgimport the volume group so that it can be used:

jupiter:~# vgimport vgbackup0_jupiter
  Volume group "vgbackup0_jupiter" successfully imported
jupiter:~# vgs vgbackup0_jupiter
  VG                #PV #LV #SN Attr  VSize   VFree  
  vgbackup0_jupiter   1   1   0 wz--n 372.61G 279.46G
jupiter:~# 

activate the volume you care about, and switch it to read-only (so you don't destroy the backups by accident while trying to recover!)

jupiter:~# lvs vgbackup0_jupiter
  LV      VG                Attr   LSize  Origin Snap%  Move Copy% 
  backup0 vgbackup0_jupiter -wi--- 93.15G                          
jupiter:~# lvchange -ay -pr vgbackup0_jupiter/backup0
  Logical volume "backup0" changed
jupiter:~# lvs vgbackup0_jupiter
  LV      VG                Attr   LSize  Origin Snap%  Move Copy% 
  backup0 vgbackup0_jupiter -ri-a- 93.15G                          
jupiter:~# 

mounting the recovery volume

Create a place to mount the volume, and mount it. remember to mount it read-only:

jupiter:~# TODAY=$(date +%Y%m%d)
jupiter:~# mkdir /var/local/backups/recovery.$TODAY
jupiter:~# mount -o ro /dev/vgbackup0_jupiter/backup0 /var/local/backups/recovery.$TODAY   
jupiter:~# 

look at the differences

you can see what might have changed:

jupiter:~# diff -qr /srv/calfs/home/ /var/local/backups/recovery.$TODAY/srv/calfs/home/ >/var/local/backups/changes.$TODAY 
jupiter:~# 

recovering data

you should be able to use simple tools like rsync and cp to pull out old versions of data that you need to pull out.

clean up

when yer done, you should clean up. unmount the recovery volume, deactivate it, and export the volume group:

jupiter:~# umount /var/local/backups/recovery.$TODAY
jupiter:~# lvchange -an vgbackup0_jupiter/backup0
jupiter:~# vgexport vgbackup0_jupiter
  Volume group "vgbackup0_jupiter" successfully exported
jupiter:~# 

see also