LVM snapshots are a simple and fast way to "snapshot" the current file system. They are (probably) mainly used to create backups from the snapshot LV or to use the snapshot as backup itself.
But it can also be a huge time saver! I recently wanted to replace a manually installed Tomcat through the Debian packages. I knew that would change a lot of the current system (e.g. openjdk being used instead of Oracle JDK), I wanted to make sure I have a rollback.
The machine on which the Tomcat is installed is an LXC running on its own dedicated LVM file system. Before installing the tomcat7 packages, I took a LV snapshot:
# lvcreate -L10g -s -n lxc12snapshot /dev/vgdata/lxc12
Logical volume "lxc12snapshot" created
I then installed the packages in the LXC... to then realize that it breaks a lot of the current installation. I tried to remove all the packages with "apt-get remove" and "apt-get purge" but some configurations still remained:
# apt-get purge tomcat7 tomcat7-admin tomcat7-common tomcat7-user openjdk-7-jdk
# grep tomcat /etc/passwd
tomcat7:x:107:109::/usr/share/tomcat7:/bin/false
Instead of trying to manually clean up everything, I can use my fallback! Yay!
After halting the LXC in question, I first checked out the status of the current LV's:
# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
lxc12snapshot vgdata swi-a-s- 10.00g lxc12 4.80
lxc12 vgdata owi-aos- 20.00g
Before the revert to the snapshot, the LV needs to be unmounted in case it is:
# umount /var/lib/lxc/lxc12/rootfs
Important note: If you forget the umount, you will run into an error (merging of snapshot will occur on next activation) on the next step. Therefore, make sure to umount the LV!
And then the rollback can happen (the snapshot will be merged with the current LV):
# lvconvert --merge /dev/vgdata/lxc12snapshot
Merging of volume lxc12snapshot started.
lxc12: Merged: 4.8%
lxc12: Merged: 3.4%
lxc12: Merged: 1.4%
lxc12: Merged: 0.0%
lxc12: Merged: 0.0%
Merge of snapshot into logical volume lxc12 has finished.
Logical volume "lxc12snapshot" successfully removed
This took about 2 minutes.
I then remounted the LV and started the container.
# mount /dev/mapper/vgdata-lxc12 /var/lib/lxc/lxc12/rootfs
# lxc-start -n lxc12 -d -c /var/lib/lxc/lxc12/console.out
VoilĂ . Easy rollback which took only a couple of minutes.
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