LXC: cloning a container snapshot into a new container

From lxadm | Linux administration tips, tutorials, HOWTOs and articles
Jump to: navigation, search

If you use LXC, one of it's nice features are snapshots. When paired with a copy-on-write filesystem like btrfs, it lets you restore a snapshot of a container into a new container in seconds.

This can be useful, for example, if you want to experiment with some potentially dangerous changes in the database.

Assuming your container's name is "backupslave" - first get a list of all existing snapshots for a given container:

# lxc-snapshot -L -n backupslave
snap53 (/var/lib/lxcsnaps/backupslave) 2016:08:07 03:03:32
snap7 (/var/lib/lxcsnaps/backupslave) 2016:08:08 03:04:11
snap9 (/var/lib/lxcsnaps/backupslave) 2016:08:09 03:04:57
snap42 (/var/lib/lxcsnaps/backupslave) 2016:08:10 03:04:59
snap5 (/var/lib/lxcsnaps/backupslave) 2016:08:11 03:05:05
snap6 (/var/lib/lxcsnaps/backupslave) 2016:08:12 03:04:58

Assuming you want to restore the snapshot dated "2016:08:12 03:04:58" as a new container called "backupslave-2016-08-12", you would run the following command:

# lxc-snapshot -n backupslave -r snap6 -N backupslave-2016-08-12