{"id":2624,"date":"2020-04-10T00:35:43","date_gmt":"2020-04-10T00:35:43","guid":{"rendered":"https:\/\/wiki.thomasandsofia.com\/?p=2624"},"modified":"2020-04-10T01:48:52","modified_gmt":"2020-04-10T01:48:52","slug":"5-lvm-snapshots","status":"publish","type":"post","link":"https:\/\/wiki.thomasandsofia.com\/?p=2624","title":{"rendered":"5. LVM Snapshots"},"content":{"rendered":"<p><a href=\"\/4-thin-provisioned-logical-volumes\/\">&lt; 4 Thin Provisioning<\/a> | <a href=\"\/lvm-commands\/\">Commands<\/a> | <a href=\"\/6-metadata-recover-of-a-physical-volume\/\">6 Metadata Recovery of a Physical Volume &gt;<\/a><\/p>\n<h1>30 &#8211; 32 Snapshots<\/h1>\n<p><a href=\"https:\/\/www.udemy.com\/course\/a-complete-guide-on-linux-lvm\/learn\/lecture\/13062442#overview\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/course\/a-complete-guide-on-linux-lvm\/learn\/lecture\/13062442#overview<\/a><\/p>\n<h2>30. Overview<\/h2>\n<ul>\n<li>An LVM Snapshot is an exact copy of an LVM partition that has all the data from the LVM volume from the time the snapshot was created.\n<ul>\n<li>An advantage of LVM snapshots is that they can be used to significantly reduce the amount of time that your services\/databases are down during backups because a snapshot is usually created in fractions of a second.<\/li>\n<li>After a snapshot has been created, you can backup the snapshot while your services and databases are in normal operation.<\/li>\n<\/ul>\n<\/li>\n<li>LVM snapshots are very space efficient.\u00a0 Only the data and metadata are copied.\u00a0 As the amount of content increases, so will the size of the snapshot.\n<ul>\n<li>Snapshots should not be kept for a long time as they will continue to consume disk space.\u00a0 In these cases, a backup is preferred over a snapshot.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>31. Lab 1<\/h2>\n<p><a href=\"https:\/\/www.udemy.com\/course\/a-complete-guide-on-linux-lvm\/learn\/lecture\/13062450#overview\" target=\"_blank\" rel=\"noopener\">https:\/\/www.udemy.com\/course\/a-complete-guide-on-linux-lvm\/learn\/lecture\/13062450#overview<\/a><\/p>\n<pre># create logical volume 'data'\r\nlvcreate -L 1G -n data VG\r\n# mount the LV\r\nmkfs -t ext4 \/dev\/VG\/data\r\nmkdir \/mnt\/data\r\nmount \/dev\/VG\/data \/mnt\/data\r\n# put some files on it - 100MB total\r\ncp 20mb.file \/mnt\/data\r\ncp 30mb.file \/mnt\/data\r\ncp 50mb.file \/mnt\/data\r\n# Create a snapshot (Size Matters!  See Note!)\r\nlvcreate -L 120M -s -n data_snap \/dev\/VG\/data\r\n  Logical volume \"data_snap\" created.\r\n# Mount the snapshot to see what is there\r\nmkdir \/mnt\/data_snapshot\r\nmount \/dev\/VG\/data_snap \/mnt\/data_snapshot\r\nls \/mnt\/data_snapshot\r\n  20mb.file\r\n  30mb.file\r\n  50mb.file<\/pre>\n<h4>Things to note:<\/h4>\n<ul>\n<li>The snapshot LV size will be the same as the volume you took the snapshot from<\/li>\n<li>The COW-table size will be the size you allocated for the snapshot volume\n<ul>\n<li>If the used disk space of the &#8216;source&#8217; LV later increases beyond this volume, the snapshot will become corrupt!<\/li>\n<li>Watch Lab 32 for more information.<\/li>\n<li><strong>It may be possible to extend the snapshot volume to match the original&#8217;s used disk space to avoid corruption.<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre># lvdisplay \/dev\/VG\/data_snap\r\n  --- Logical volume ---\r\n  LV Path \/dev\/VG\/data_snap\r\n  LV Name snap_data\r\n  VG Name system\r\n  LV UUID NwJSQu-NjIr-7Qn0-Wo0q-ig7d-3apy-eChdWD\r\n  LV Write Access read\/write\r\n  LV Creation host, time nds18-rdssrv, 2017-09-13 04:23:35 -0400\r\n  LV snapshot status INACTIVE destination for data\r\n  LV Status available\r\n  # open 0\r\n  LV Size 1.00 GiB\r\n  Current LE 256\r\n  COW-table size 120.00 Mib\r\n  COW-table LE 50\r\n  Snapshot chunk size 4.00 KiB\r\n  Segments 1\r\n  Allocation inherit\r\n  Read ahead sectors auto\r\n  - currently set to 8192\r\n  Block device 253:12<\/pre>\n<h2>How to restore from a snapshot<\/h2>\n<pre># delete all files from the original LV\r\ncd \/mnt\/data\r\nrm -rf *\r\n# Unmount the 'corrupt' LV\r\numount \/dev\/data\r\n# Merge the snapshot into the corrupt LV\r\n# * Since we do not tell the snapshot what to merge into, \r\n# * it must know from its metadata?\r\nlvconvert --merge \/dev\/VG\/data_snap\r\n# Mount the original LV back\r\nmount \/mnt\/data \/dev\/VG\/data\r\nls \/mnt\/data\r\n  20mb.file\r\n  30mb.file\r\n  50mb.file<\/pre>\n<h2>31. Lab 2 &#8211; Updating a snapshot<\/h2>\n<pre># show existing files\r\nls \/mnt\/data\r\n  20mb.file\r\n  30mb.file\r\n  50mb.file\r\n# take a new snapshot\r\nlvcreate -L120 -s -n data_snap \/dev\/VG\/data\r\n# create some new files\r\n???<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt; 4 Thin Provisioning | Commands | 6 Metadata Recovery of a Physical Volume &gt; 30 &#8211; 32 Snapshots https:\/\/www.udemy.com\/course\/a-complete-guide-on-linux-lvm\/learn\/lecture\/13062442#overview 30. Overview An LVM Snapshot is an exact copy of an LVM partition that has all the data from the LVM volume from the time the snapshot was created. An advantage of LVM snapshots is ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/wiki.thomasandsofia.com\/?p=2624\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56],"tags":[],"class_list":["post-2624","post","type-post","status-publish","format-standard","hentry","category-logical-volume-manager"],"_links":{"self":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/2624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2624"}],"version-history":[{"count":5,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/2624\/revisions"}],"predecessor-version":[{"id":2632,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/2624\/revisions\/2632"}],"wp:attachment":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}