Lvm snapshot

From Finninday
Jump to: navigation, search

See http://www.howtoforge.com/linux_lvm_snapshots for reference.

First, I added a new disk and did a pvcreate on it. Then I added the new disk to the same volume group that the root partition is in, namely "Ubuntu".

Command to create an lvm snapshot in order to do a backup of the root partition.

lvcreate -L250G -s -n root-snap /dev/Ubuntu/root
root@weasel:~# lvscan
File descriptor 5 left open
File descriptor 6 left open
File descriptor 7 left open
File descriptor 8 left open
  ACTIVE            '/dev/vg00/big' [232.88 GB] inherit
  ACTIVE   Original '/dev/Ubuntu/root' [226.77 GB] inherit
  ACTIVE            '/dev/Ubuntu/swap_1' [5.88 GB] inherit
  ACTIVE   Snapshot '/dev/Ubuntu/root-snap' [250.00 GB] inherit

Connect the USB drive where the backup will be stored.

root@weasel:/media# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/Ubuntu-root
                     234052488 111205240 110957996  51% /
varrun                  514528       408    514120   1% /var/run
varlock                 514528         0    514528   0% /var/lock
udev                    514528        92    514436   1% /dev
devshm                  514528         0    514528   0% /dev/shm
lrm                     514528     43040    471488   9% /lib/modules/2.6.24-19-generic/volatile
/dev/mapper/vg00-big 240361984 195076932  33075288  86% /big
/dev/sdd1            484535504 238344264 221772040  52% /media/disk

The USB disk was automounted on /media/disk.

Do the backup.

root@weasel:/media/disk# time dd if=/dev/Ubuntu/root-snap of=/media/disk/weasel-root.dd
475570176+0 records in
475570176+0 records out
243491930112 bytes (243 GB) copied, 13529.5 s, 18.0 MB/s

real	225m29.539s
user	3m0.511s
sys	111m46.531s

That's about 4 hours for 250G at 18M/sec. If root was only 5G it should be more like 5 minutes.

Verify the backup and disconnect the USB drive.

Destroy the snapshot.

root@weasel:/media/disk# lvremove /dev/Ubuntu/root-snap
File descriptor 5 left open
File descriptor 6 left open
File descriptor 7 left open
File descriptor 8 left open
Do you really want to remove active logical volume "root-snap"? [y/n]: y
  Logical volume "root-snap" successfully removed