Quick LVM Snapshotting

Assuming your LVM has a layout that looks like this:

  --- Logical volume ---
  LV Name                /dev/system/root
  VG Name                system
  LV UUID                LPCEwv-sku2-Ea3N-vIgB-pcA9-OFSA-3rOzQd
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/system/vz
  VG Name                system
  LV UUID                GaN7YC-iqO5-E9j9-Y4Ot-dlbu-dEeQ-hS0lUS
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                840.00 GiB
  Current LE             215040
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

You create a snapshot using

lvcreate -L 10G -n snapshot_name -s /dev/system/snapshot_source

-L 10G is the size that is allocated to the snapshot. The snapshot can be removed afterwards using

lvremove /dev/system/*snapshot_name*

Backup can be performed using 'dd' or rsync, using

rsync -rlpogtSh *source* *destination*
rsync -rlpogtSh -4 -e 'ssh -p 2222' root@remotehost:/mnt/vzsnap/private .

The latter one copies from a remote host, using a non-standard ssh-port for scp and forcing IPv4 (-4). The rsync files are used as follows:

-r recursive

-l copy symlinks as symlinks

-p preserve permissions

-o preserve owner (superuser only)

-g preserve group (superuser only)

-t preserve modification times

-S handle sparse files efficiently

-h output numbers in a human-readable format

--progress show progress during transfer can be used if desired. I would advise against it if you are not transferring huge files since the progress indicator creates quite a bit of overhead that can significantly slow down the operation.

© 2010-2015 Stefan Birgmeier
birki@21er.org