LVM Snapshot

lvmdiskscan
     pvs -o+pv_used
     lsblk

 lvcreate --size 3G --snapshot --name storage_snapshot /dev/storage/website
   lvdisplay /dev/storage/website
    mkfs.ext4 /dev/storage/storage_snapshot
    mkdir /storage_data/websitesnapshot
     mount /dev/storage/storage_snapshot /storage_data/websitesnapshot
   e2label /dev/storage/storage_snapshot "Web Snapshot"
     lvs

 


Preparing to Create an LVM Snapshots

An LVM snapshot has to be created in the same Volume Group as the source LV. Using CoW (Copy on Write) Technology the underlying storage has to be the same. Allowing unchanged data in the snapshot to be read from the original LV source. Our Volume Group is full, so we will delete the existing Logical Volume and recreate it a a smaller size. We will also use two mountpoints, /mnt/original and /mnt/snap.

 # umount /mnt
 # mkdir /mnt/{original,snap}
 # lvremove /dev/vg1/lv1
 # lvcreate -n lv1 -L 600m vg1
 # mkfs.ext4 /dev/vg1/lv1
 # mount /dev/vg1/lv1 /mnt/original

After....

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
umount /mnt/volume1
Deactivate and activate you volume:

# lvchange -a n /dev/volume_group/volume1
# lvchange -a y /dev/volume_group/volume1
mount /dev/volume_group/volume1 /mnt/volume1
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


lvmdiskscan
 /dev/centos7/root             [       9.31 GiB]
  /dev/vda1                     [     953.00 MiB]
  /dev/centos7/swap             [      <2.80 GiB]
  /dev/vda2                     [      22.37 GiB] LVM physical volume
  /dev/centos7/home             [     956.00 MiB]
  /dev/centos7/storage_snapshot [      <4.66 GiB]
  /dev/centos7/storage_cache    [      <4.66 GiB]
  /dev/vdb                      [      13.00 GiB]
  6 disks
  1 partition
  0 LVM physical volume whole disks
  1 LVM physical volume


pvs -o+pv_used
 PV         VG      Fmt  Attr PSize   PFree  Used
  /dev/vda2  centos7 lvm2 a--  <22.37g 12.00m <22.36g


lsblk

NAME                         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda                          252:0    0   25G  0 disk
├─vda1                       252:1    0  953M  0 part /boot
└─vda2                       252:2    0 22.4G  0 part
  ├─centos7-root             253:0    0  9.3G  0 lvm  /
  ├─centos7-swap             253:1    0  2.8G  0 lvm  [SWAP]
  ├─centos7-home             253:2    0  956M  0 lvm  /home
  ├─centos7-storage_snapshot 253:3    0  4.7G  0 lvm  /storage/snapshot
  └─centos7-storage_cache    253:4    0  4.7G  0 lvm  /storage/cache
vdb                          252:16   0   13G  0 disk


umount /storage/snapshot


lvremove /dev/centos7/storage_snapshot


lvcreate --size 4.6G --snapshot --name storage_snapshot /dev/centos7/root

 Rounding up size to full physical extent 4.60 GiB
  Logical volume "storage_snapshot" created.


lvdisplay /dev/centos7/root

  --- Logical volume ---
  LV Path                /dev/centos7/root
  LV Name                root
  VG Name                centos7
  LV UUID                tyxhHd-HZ5n-AaNN-mA5q-3nMr-Uh5c-dZNUj7
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-03-29 19:03:26 +0000
  LV snapshot status     source of
                         storage_snapshot [active]
  LV Status              available
  # open                 1
  LV Size                9.31 GiB
  Current LE             2384
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0


lvs

 LV               VG      Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home             centos7 -wi-ao---- 956.00m
  root             centos7 owi-aos---   9.31g
  storage_cache    centos7 -wi-ao----  <4.66g
  storage_snapshot centos7 swi-aos---   4.60g      root   0.02
  swap             centos7 -wi-ao----  <2.80g


 df -Th

Filesystem                           Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos7-root             ext4      9.1G  1.8G  6.9G  21% /
devtmpfs                             devtmpfs  484M     0  484M   0% /dev
tmpfs                                tmpfs     496M     0  496M   0% /dev/shm
tmpfs                                tmpfs     496M  6.8M  489M   2% /run
tmpfs                                tmpfs     496M     0  496M   0% /sys/fs/cgroup
/dev/vda1                            ext4      922M  105M  754M  13% /boot
/dev/mapper/centos7-storage_cache    ext4      4.5G   19M  4.2G   1% /storage/cache
/dev/mapper/centos7-home             xfs       953M   33M  921M   4% /home
tmpfs                                tmpfs     100M     0  100M   0% /run/user/0
/dev/mapper/centos7-storage_snapshot ext4      9.1G  1.8G  6.9G  21% /storage/snapshot


df -aTh {check, whether SNAPSHOT was mounted}| /etc/mtab | /proc/mounts

Filesystem                           Type        Size  Used Avail Use% Mounted on
rootfs                               -              -     -     -    - /
sysfs                                sysfs          0     0     0    - /sys
proc                                 proc           0     0     0    - /proc
devtmpfs                             devtmpfs    484M     0  484M   0% /dev
securityfs                           securityfs     0     0     0    - /sys/kernel/security
tmpfs                                tmpfs       496M     0  496M   0% /dev/shm
devpts                               devpts         0     0     0    - /dev/pts
tmpfs                                tmpfs       496M  6.8M  489M   2% /run
tmpfs                                tmpfs       496M     0  496M   0% /sys/fs/cgroup
cgroup                               cgroup         0     0     0    - /sys/fs/cgroup/systemd
pstore                               pstore         0     0     0    - /sys/fs/pstore
cgroup                               cgroup         0     0     0    - /sys/fs/cgroup/memory
cgroup                               cgroup         0     0     0    - /sys/fs/cgroup/cpu,cpuacct
cgroup                               cgroup         0     0     0    - /sys/fs/cgroup/perf_event
cgroup                               cgroup         0     0     0    - /sys/fs/cgroup/cpuset
cgroup                               cgroup         0     0     0    - /sys/fs/cgroup/net_cls,net_prio
cgroup                               cgroup         0     0     0    - /sys/fs/cgroup/devices
cgroup                               cgroup         0     0     0    - /sys/fs/cgroup/pids
cgroup                               cgroup         0     0     0    - /sys/fs/cgroup/freezer
cgroup                               cgroup         0     0     0    - /sys/fs/cgroup/hugetlb
cgroup                               cgroup         0     0     0    - /sys/fs/cgroup/blkio
configfs                             configfs       0     0     0    - /sys/kernel/config
/dev/mapper/centos7-root             ext4        9.1G  1.8G  6.9G  21% /
selinuxfs                            selinuxfs      0     0     0    - /sys/fs/selinux
systemd-1                            autofs         0     0     0    - /proc/sys/fs/binfmt_misc
hugetlbfs                            hugetlbfs      0     0     0    - /dev/hugepages
mqueue                               mqueue         0     0     0    - /dev/mqueue
debugfs                              debugfs        0     0     0    - /sys/kernel/debug
/dev/vda1                            ext4        922M  105M  754M  13% /boot
/dev/mapper/centos7-storage_cache    ext4        4.5G   19M  4.2G   1% /storage/cache
/dev/mapper/centos7-home             xfs         953M   33M  921M   4% /home
tmpfs                                tmpfs       100M     0  100M   0% /run/user/0
/dev/mapper/centos7-storage_snapshot ext4        9.1G  1.8G  6.9G  21% /storage/snapshot




lvs -o name,lv_ancestors,lv_descendants centos7

  LV               Ancestors Descendants
  home
  root                       storage_snapshot
  storage_cache
  storage_snapshot root
  swap


RECOVERING SNAPSHOT

umount /storage/snapshot


df -h {verify}


lvconvert --merge /dev/centos7/storage_snapshot
 


Falko Timme' method:

mkdir /backups
 

tar -pczf /backups/root.tar.gz /storage/snapshot

 

And if you like to do a bitwise backup (i.e. an image), you can do it like this:

dd if=/dev/centos7/storage_snapshot of=/backups/root.dd

server1:~# dd if=/dev/centos7/storage_snapshot of=/backups/root.dd

19513344+0 records in
19513344+0 records out
9990832128 bytes (10 GB) copied, 320.059 seconds, 31.2 MB/s

umount /storage/snapshot
lvremove /dev/centos7/storage_snapshot

That's it, you've just made your first backup from an LVM snapshot.

Restore A Backup

This chapter is about restoring the /dev/centos7/root volume from the dd image we've created in the previous chapter. Normally you can restore a backup from the same running system if the volume that you want to restore doesn't contain system-critical files. But because the /dev/centos7/root volume is the system partition of our machine, we must use a rescue system or Live-CD to restore the backup. The rescue system/Live-CD must support LVM.

 

To restore the /dev/centos7/root volume, I boot the system from the Debian Etch Netinstall CD and type in rescue at the boot prompt:

Tags: