announcing lxc-snapshot

In April, lxc-clone gained the ability to create overlayfs snapshot clones of directory backed containers. In may, I wrote a little lxc-snap program based on that which introduced simple ‘snapshots’ to enable simple incremental development of container images. But a standalone program is not only more tedious to discover and install, it will also tend to break when the lxc API changes.

Now (well, recently) the ability to make snapshots has been moved into the lxc API itself, and the program lxc-snapshot, based on that, is shipped with lxc. (Leaving lxc-snap happily deprecated.)

As an example, let’s say you have a container c1, and you want to test a change in its /lib/init/fstab. You can snapshot it,

sudo lxc-snapshot -n c1

test your change, and, if you don’t like the result, you can recreate the original container using

sudo lxc-snapshot -n c1 -r snap0

The snapshot is stored as a full snapshot-cloned container, and restoring is done as a copy-clone using the original container’s backing store type. If your original container was /var/lib/lxc/c1, then the first snapshot will be /var/lib/lxcsnaps/c1/snap0, the next will be /var/lib/lxcsnaps/c1/snap1, etc.

There are some complications. Restoring a container to its original name as done in the above example will work if you have a btrfs backed container. But if your original container was directory backed, then the snapshot will be overlayfs-based, and will depend on the original container’s rootfs existing. Therefore it will pin the original container, and you’ll need to restore the snapshot to a new name, i.e.

sudo lxc-snapshot -n c1 -r snap0 c2

If you want to see a list of snapshots for container c1, do

sudo lxc-snapshot -n c1 -L

If you want to store a comment with the snapshot, you can

echo "This is before my /lib/init/fstab change" >> comment1
sudo lxc-snapshot -n c1 -c comment1

And then when you do

sudo lxc-snapshot -n c1 -L -C

you’ll see the snapshot comments after each snapshot.

There is certainly room for lots of feature development in lxc-snapshot. It could add removal support, improve comment snapshot support, sort snapshots in the listing, and for that matter could work around the overlayfs shortcomings to allow restoring a container to its original name. So if someone is looking for something to do, here’s one of many things waiting for an owner 🙂 Meanwhile it seems to me plenty useful as is.

Have fun!

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

5 Responses to announcing lxc-snapshot

  1. Just for the teference: if you show example usage of command line, it makes sense to use –long versions of command line switches, so that people with no experience with the tool can understand the examples better.

    • s3hh says:

      Hm, maybe side by side would make sense… I really dislike long args on the whole, but you may be right.

    • Stuart says:

      Agree. The first time I remember when I first saw “tar -xvzf” it put me off, but tar –extract –verbose –gzip –file is self-explanatory and thus “less scary”.

      • Richard Hughes says:

        A quick man gzip will show you what the short switches mean and it is worth the additional effort when you first encounter a new command. In some cases even a long switch will not give you the understanding you should have before running a command. Better to use short commands and encourage people to look them up. If people run commands without understanding what they do they they deserve the outcome.

      • s3hh says:

        True, but if I’m trying to show something in my post, having to switch to another screen to look things up can take away from my point. If I can remember to do so, I think the ideal would be to show both in the post.

Leave a comment