Wednesday, October 8, 2008

LVM snapshots

Here is a script to create LVM snapshots in Linux. It is a skeleton only provided for your modification and my reference, but I am using AoE storage as my PV.

#create PV

pvcreate /dev/etherd/e1.0

#create VG

vgcreate cascade /dev/etherd/e1.0

#create LV

lvcreate cascade -n original -L 500G

#make XFS filesystem

mkfs.xfs /dev/cascade/original

#mount (and use) LV

mount /dev/cascade/original /mnt

#freeze filesystem (will hang processes that are using IO on /mnt)

xfs_freeze -f /mnt

#create snapshot of original (works best if it is the same size)

lvcreate -s /dev/cascade/original -n backup -L 500G

#mount snapshot

mount -o nouuid,ro /dev/cascade/backup /mnt2

#backup directory with rsync or backup utility

#unmount LV

umount /mnt2

#remove snapshot

lvremove /dev/cascade/backup

#additional information is found here: http://arstechnica.com/articles/columns/linux/linux-20041013.ars and here: http://tldp.org/HOWTO/LVM-HOWTO/snapshots_backup.html

No comments: