Storage » StorageBackup » StorageLVMSnap
Read
http://www.howtoforge.com/linux_lvm_snapshots
Backup with LVM snapshot
LVM supports snapshot partition which creates a snapshot of an existing partition. How it works:- You have a source partition to backup
- When you creates the snapshot partition, data are not actually cloned to the snapshot partition. Instead, all writing to the source partition (the delta) will be performed to the snapshot partition instead. Hence your /opt partition will remain in a consistent state.
- Backup the snapshot partition. Although the snapshot partition holds the delta only, it also serves as the mount point to the consistent state of your source partition.
- Once the backup is done, unmount the snapshot partition, and remove it. All the delta will then be written back to the source partition.
Extending volume group with a USB drive
Plugin the USB hard drive, do a dmesg to find out its device name. Mine is /dev/sdc. I'm going to use the entire disk.pvcreate /dev/sdc vgextend vg0 /dev/sdc vgdisplay --- Volume group --- VG Name vg0 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 3 Act PV 3 VG Size 46.30 GB PE Size 4.00 MB Total PE 11852 Alloc PE / Size 10420 / 40.70 GB Free PE / Size 1432 / 5.59 GB VG UUID YKS0RP-039W-oXcu-9Kdk-X38i-edgr-idYouj
So now I have extended by vg0 with my usb drive.
Creating the snapshot
Now I'll actually create the snapshot partition. The size of your snapshot partition really depends on your anticipation on the delta size during the backup. During this test, I'll create some 100M of delta, so I'll create a snapshot partition of 200M for ease of illustration.lvcreate -L 200M -s -n opt_snapshot /dev/vg0/lv_opt Logical volume "opt_snapshot" created
Checking snapshot status
Use the lvs command to display LVM status. You can see that the snapshot partition is nearly empty. That's because at this point, no delta is created.LV VG Attr LSize Origin Snap% Move Log Copy% lv_opt vg0 owi-ao 39.24G lv_swap vg0 -wi-ao 1.46G opt_snapshot vg0 swi-a- 200.00M lv_opt 0.01
Making changes to source partition
To simulate an update on the source partition, I'm going to create a 100M file in /opt. I can see that my USB drive's LED is blinking, meaning the new file is now being written to the snapshot partition.dd if=/dev/urandom of=/opt/some_file bs=1M count=100 100+0 records in 100+0 records out 104857600 bytes (105 MB) copied, 20.651 s, 5.1 MB/s
Now do a lvs to check the status. You can see that the snapshot partition is now approximately 50% full.
LV VG Attr LSize Origin Snap% Move Log Copy% lv_opt vg0 owi-ao 39.24G lv_swap vg0 -wi-ao 1.46G opt_snapshot vg0 swi-a- 200.00M lv_opt 50.25
Actually perform the backup
Now that you have a snapshot of your source partition, it's time to actually do a backup. Just mount the snapshot partition in read-only mode, and then dump it or simply use tar the files in the snapshot partition.Removing the snapshot partition
After you have backed up the snapshot partition, you can remove it.umount /mnt/snapshot lvremove /dev/vg0/opt_snapshot
Everything's done, I want to unplug the USB drive
Remove /dev/sdc from your volume groupvgreduce vg0 /dev/sdc Removed "/dev/sdc" from volume group "vg0"
Now unplug your USB drive!
What happens if the snapshot partition is full before the backup is done?
My snapshot partition is 200M in size. I've already created a file of 100M. Let's try that by creating another 150M file in /opt.dd if=/dev/urandom of=/opt/some_another_file bs=1M count=150 150+0 records in 150+0 records out 157286400 bytes (157 MB) copied, 30.3696 s, 5.2 MB/s
Do a tail -f /var/log/message and you should see an error:
kernel: device-mapper: snapshots: Invalidating snapshot: Unable to allocate exception.
The snapshot partition is "invalidated" or in other words dropped. Now if you try to create yet another dummy file, you will notice your USB drive is no longer blinking. That is because the writing is actually written to the source partition from this point on. At this point, there is nothing much you can do besides removing the snapshot partition.
CategoryCool
There are no comments on this page. [Add comment]