|
LVM Snapshots - Snapshot Creation |
|
|
|
|
Written by Tom Hirt
|
|
Monday, 18 May 2009 13:10 |
|
Page 2 of 2
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>
In the following example, we will create a 500MB snapshot LV of an existing LV, lets being:
- 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
[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 ~]#
|
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.)
- Verify the snapshot has been created
| [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 |
|
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.
- 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 /]#
|
Nice work, you now know how-to snapshot a LV. Good luck!
Add this page to your favorite website
|
|
Last Updated on Tuesday, 02 June 2009 10:27 |