This post is mostly for my own reference. I am posting it here to possibly aid someone else in the future.
This post is based on a very good article from the Linux Gazette that has been a very good point of reference for me: http://linuxgazette.net/114/kapil.html
That article does a very good job of clarifying the concepts behind various device mapper usage scenarios. That article is very ambitious- it covers a lot of material in a short space. The one usage scenario that I found difficult to grasp is when working with the snapshot-origin target. Using the above article as I guide, in this post I will attempt to filter the steps necessary to work with the snapshot-origin target only; I will ignore simple snapshots and encrypted snapshots. By the way, the basic motivation for using snapshot-origin target is to obtain consistent backups of live filesystems.
My test environment:
Hardware: | ||
Motherboard | : | Intel SAI2 w/ 2 x 1.4G P3 CPUS |
RAM | : | 4G |
Disk controller | : | Silicon Image, Inc. SiI 3114 (not in RAID mode) |
Physical disks | : | 2 x 1 TB disks (sda, sdb) |
RAID Mode | : | partition based RAID 1 using software raid provided by Linux kernel |
Software: | ||
Distribution | : | Slackware 13.1 |
Linux kernel | : | 2.6.33.7 (my own config) |
Disk filesystem | : | xfs |
Here is the partition table for sdb (sda is identical):
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xe... Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ fd Linux raid autodetect /dev/sdb2 1307 2612 10490445 83 Linux /dev/sdb3 2613 3135 4200997+ fd Linux raid autodetect /dev/sdb4 3136 121601 951578145 5 Extended /dev/sdb5 3136 3658 4200966 83 Linux /dev/sdb6 3659 5226 12594928+ 83 Linux /dev/sdb7 5227 121601 934782156 fd Linux raid autodetectFor reference, here is the relevent RAID info:
# cat /proc/mdstat md2 : active raid1 sdb7[0] sda7[1] 934782080 blocks [2/2] [UU]
For this problem I will document some of the steps to prepare a backup of /dev/md2 using a snapshot-origin object using a COW snapshot allocated on /dev/sdb6. Hopefully, that is enough information to make the problem concrete enough to follow along.
Step 0: I am not using LVM; I am manipulating device mapper objects directly. To use this technique, I need to create a device mapper object representing the RAID device. This is necessary to be able to suspend the device using the dmsetup commands, etc.
When the device is being prepared for use, setup the object before mounting it.
# echo 0 $(blockdev --getsize /dev/md2) linear /dev/md2 0 | dmsetup create md2
Also, create a duplicate device:
# dmsetup table md2 | dmsetup create md2_dup
Mount it:
# mount /dev/mapper/md2 /mnt/md2
Notes:
Step 1: Prepare COW snapshot and finally activate it.
# dd if=/dev/zero of=/dev/sdb6 bs=512 count=32 # dmsetup suspend md2 # echo 0 $(blockdev --getsize /dev/mapper/md2_dup) snapshot /dev/mapper/md2_dup /dev/sdb6 p 32 |dmsetup create cow # echo 0 $(blockdev --getsize /dev/mapper/md2_dup) snapshot-origin /dev/mapper/md2_dup | dmsetup create origin # dmsetup table origin | dmsetup load md2 # dmsetup resume md2
Notes:
Step 2: Mount COW Snapshot.
# mount -o nouuid -o ro /dev/mapper/cow /mnt/md2_snap
Notes:
Step 3: Use the backup method of your choice to perform a backup of the frozen snapshot mounted on /mnt/md2_snap. Normal file operations will continue on "live" filesystem mounted on /mnt/md2. The specific backup method is not shown here.
Step 4: Obtain miscellaneous statistics while snapshot is in effect.
# dmsetup table md2 0 1869564160 snapshot-origin 253:1 # dmsetup table md2_dup 0 1869564160 linear 9:2 0 # dmsetup status cow 0 1869564160 snapshot 6496/25189857 64
Notes:
Step 5: Tear down the snapshot and restore to initial table to device.
# dmsetup suspend md2 # dmsetup remove origin # dmsetup remove cow # dmsetup table md2_dup | dmsetup load md2 # dmsetup resume md2
Step 6: When ready to do another snapshot backup, jump back to Step 1.
Final Remarks
Page Last Modified: 2010-12-10