Difference between revisions of "Lvm snapshot"

From Finninday
Jump to: navigation, search
(New page: 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 i...)
 
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
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".
 
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".
  
Line 18: Line 20:
  
 
Connect the USB drive where the backup will be stored.
 
Connect the USB drive where the backup will be stored.
 +
<pre>
 +
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
 +
</pre>
 +
The USB disk was automounted on /media/disk.
  
 
Do the backup.
 
Do the backup.
 +
<pre>
 +
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
 +
</pre>
 +
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.
 
Destroy the snapshot.
 +
<pre>
 +
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
 +
</pre>

Latest revision as of 14:52, 25 June 2008

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