| LVM Snapshots |
| Snapshot Creation |
| All Pages |
LVM Snapshots Overview
Continuing with our LVM how to series, in this KB, we will build on the knowledge from our LVM Configuration KB, and explore logical volume (LV) snapshots. We will show you how to create a LV snapshot which can then be mounted for a backup or some other purpose.
Linux administrators typically use LV snapshots for backups. Often times, running a backup can take anywhere from a couple of minutes to several hours (depending on the amount of data to backup.) Depending on how busy your system, from the time the backup begins to the time it completes, some of your files could have changed with omissions to open files. Snapshots provide a means of obtaining a consistent volume (free of changes) in a matter of seconds. The snapshot (which is a exact copy of the LV taken at the time the snapshot command was run) can then be backed-up without the worry of changes to the file system or need to shutdown running databases or close open files.
LVM snapshots can only be taken from logical volumes. Non LV partitions cannot have a snapshot taken of them.
Snapshots require only a fraction of the space required by the source LV. Behind the scenes, when a snapshot is taken, the source LV is frozen while the changes to the LV are written to the LV snapshot. Thus, the size of the snapshot only needs to be large enough for the anticipated changes to the file system over the lifetime of the snapshot. So in other words, the size of the source LV has no bearing on the size requirements for the snapshot LV, but rather how many changes will be made to the source LV throughout the lifetime of the existence of the snapshot LV.
Once the snapshot is removed, the changes logged in the LV snapshot are written back to the source LV. Should a snapshot LV run out of space, the snapshot will be released.
One cautionary note with LV snapshots, they are I/O intensive. I have seen I/O performance hits by more than 50% of the snapshot LV while running with a snapshot. Therefore, you should ensure that you do not run with a snapshot LV any longer than absolutely necessary.
Snapshot Creation
Creating a logical volume (LV) snapshot is much the same process as creating a LV (see our LVM Configuration KB for details on how to create a LV.) However, when creating a LV snapshot you must use a -s command line switch in conjunction with the LV you wish to snapshot. The syntax is as follows:
- lvcreate -L <SIZE_OF_SNAPSHOT> -s -n <NAME_OF_SNAPSHOT> <LV_TO_SNAPSHOT>
- Use lvdisplay to find the name of the logical volume you wish to snapshot
[root@Linux01 ~]# lvdisplay --- Logical volume --- LV Name /dev/TCPDumpVolGRP/TCPDumpLV VG Name TCPDumpVolGRP LV UUID hYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF LV Write Access read/write LV Status available # open 1 LV Size 1.50 GB Current LE 48 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:5 ... OUTPUT TRUNCATED - Create a new 500MB snapshot from the source LV /dev/TCPDumpVolGRP/TCPDumpLV
Note: Our snapshot LV (500MB) is about 1/3 the size of the source LV (1.5 GB). As we have already said, the snapshot LV does not need to be the same size of the source. Because the snapshot LV will only contain the changes made to the source LV while its snapshot, and we know there is not a high rate of change on the source LV, we are fine using 1/3 the size (and would have probably been safe making it far less.)[root@Linux01 /]# lvcreate -L 500M -s -n BackupLV /dev/TCPDumpVolGRP/TCPDumpLV
Rounding up size to full physical extent 512.00 MB
Logical volume "BackupLV" created
[root@Linux01 ~]#
- Verify the snapshot has been created
Note: You will notice on the BackupLV that although the LV size says that it's 1.5GB, the copy-on-write (COW) table informs us that it's actually only 512MB (the source LV is 1.5GB.) Also, the percentage allocated to the snapshot is currently at 0%. As updates are made to the source LV, you'll notice this percentage will increase.[root@Linux01 ~]# lvdisplay --- Logical volume --- LV Name /dev/TCPDumpVolGRP/TCPDumpLV VG Name TCPDumpVolGRP LV UUID hYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF LV Write Access read/write LV Status available # open 1 LV Size 1.50 GB Current LE 48 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:5 --- Logical volume --- LV Name /dev/TCPDumpVolGRP/BackupLV VG Name TCPDumpVolGRP LV UUID mSWMF0-5JtO-GkAd-plBb-YIf8-1HOg-JRfV34 LV Write Access read/write LV snapshot status active destination for /dev/TCPDumpVolGRP/TCPDumpLV LV Status available # open 0 LV Size 1.50 GB Current LE 48 COW-table size 512.00 MB COW-table LE 16 Allocated to snapshot 0.00% Snapshot chunk size 4.00 KB Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:7 ... OUTPUT TRUNCATED
- We can now mount the snapshot so that it may be backed-up
[root@Linux01 /]# mkdir -p /mnt/backup
[root@Linux01 /]# mount /dev/TCPDumpVolGRP/BackupLV /mnt/backup/
[root@Linux01 /]# df -kh
Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol04 3.9G 2.2G 1.6G 59% / /dev/sda1 99M 12M 82M 13% /boot tmpfs 1006M 0 1006M 0% /dev/shm /dev/mapper/VolGroup00-LogVol00 992M 41M 901M 5% /home /dev/mapper/VolGroup00-LogVol02 992M 69M 872M 8% /tmp /dev/mapper/VolGroup00-LogVol03 2.0G 150M 1.7G 8% /var /dev/mapper/TCPDumpVolGRP-4GLV 4.0G 137M 3.7G 4% /4GLV /dev/mapper/TCPDumpVolGRP-TCPDumpLV 1.5G 920M 497M 65% /TCPDumpLV /dev/mapper/TCPDumpVolGRP-BackupLV 1.5G 920M 497M 65% /mnt/backup - Once the snapshot has been backed-up, unmount the LV and remove it
[root@Linux01 /]# umount /mnt/backup/
[root@Linux01 /]# lvremove /dev/mapper/TCPDumpVolGRP-BackupLV
Do you really want to remove active logical volume "BackupLV"? [y/n]: y
Logical volume "BackupLV" successfully removed
[root@Linux01 /]#
No comments:
Post a Comment