Using LXC containers with logical volumes (LV) is a handy way to quickly restore a complete container to a previous state. See Reverting / Restoring to a LVM snapshot as a rollback scenario for more information.
However if the LV in question is still in use, the snapshot merging process is somewhat confusing.
Within a LXC container, an application was upgraded. Prior to this, a LV snapshot was taken.
root@host:~# lvcreate -L10G -s -n wikisnapshot /dev/vglxc/inf-wiki01-t
Using default stripesize 64.00 KiB.
Logical volume "wikisnapshot" created.
This can be seen by using lvs:
root@host:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
inf-wiki01-t vglxc owi-aos--- 60.00g
wikisnapshot vglxc swi-a-s--- 10.00g inf-wiki01-t 35.19
After the application upgrade, it turned out that the new version caused problems so a restore was required.
After the LXC container was shut down, the lvconvert command was run to merge the snapshot back into the logical volume:
root@host:~# lvconvert --merge /dev/vglxc/wikisnapshot
Can't merge until origin volume is closed.
Merging of snapshot vglxc/wikisnapshot will occur on next activation of vglxc/inf-wiki01-t.
Usually the merging progress would be immediately shown here. It was at this point I realized that I forgot to umount the filesystem!
root@host:~# df -h | grep wiki
/dev/mapper/vglxc-inf--wiki01--t ext4 59G 43G 14G 76% /var/lib/lxc/inf-wiki01-t/rootfs
After umount the file system, lvconvert was run again, but this time a warning showed up:
root@host:~# umount /var/lib/lxc/inf-wiki01-t/rootfs
root@host:~# lvconvert --merge /dev/vglxc/wikisnapshot
Command on LV vglxc/wikisnapshot is invalid on LV with properties: lv_is_merging_cow .
Command not permitted on LV vglxc/wikisnapshot.
Interestingly, another lvs would not show the snapshot anymore:
root@host:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
inf-wiki01-t vglxc Owi-a-s--- 60.00g
However the LV now shows up with a capital O in the attribute. According to the man page, this means that the origin LV is being merged with the snapshot:
The lv_attr bits are:
1 Volume type: (C)ache, (m)irrored, (M)irrored without initial sync, (o)rigin, (O)rigin with merging snapshot, (r)aid,
(R)aid without initial sync, (s)napshot, merging (S)napshot, (p)vmove, (v)irtual, mirror or raid (i)mage, mirror or
raid (I)mage out-of-sync, mirror (l)og device, under (c)onversion, thin (V)olume, (t)hin pool, (T)hin pool data,
v(d)o pool, v(D)o pool data, raid or pool m(e)tadata or pool metadata spare.
However no progress whatsoever is showing up. Does this mean the merging is in progress or nothing is happening right now?
The answer is: The merging is delayed, otherwise the progress would be showing up using the lvs command.
In order that the snapshot merge can start, the LV must not be used or mounted by anything; # open value of the LV must be 0:
root@host:~# lvdisplay /dev/vglxc/inf-wiki01-t
--- Logical volume ---
LV Path /dev/vglxc/inf-wiki01-t
LV Name inf-wiki01-t
VG Name vglxc
LV UUID ngQJTX-9IfN-VWSe-MNLe-US9O-Yf0E-jmLQeU
LV Write Access read/write
LV Creation host, time nzzinfr-lxc02-test, 2017-03-10 14:46:47 +0100
LV snapshot status source of
wikisnapshot [active]
LV Status available
# open 0
LV Size 60.00 GiB
Current LE 15360
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:6
The snapshot merging can then be triggered by a refresh:
root@host:~# lvchange --refresh vglxc
As soon as this command was executed, lvs now showed a percentage value on the Data% column:
root@host:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
inf-wiki01-t vglxc Owi-a-s--- 60.00g 38.01
This value steadily decreased, until no value was shown anymore and the O attribute disappeared as well:
root@host:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
inf-wiki01-t vglxc Owi-a-s--- 60.00g 33.06
root@host:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
inf-wiki01-t vglxc -wi-a----- 60.00g
The file system could now be mounted and the container started again. Restore completed.
No comments yet.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Office PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder