Skip to content

hallyn/lxc-snap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 

Repository files navigation

lxc-snap: lxc container snapshot management tool

BACKGROUND

Lxc supports containers backed by overlayfs snapshots.  The way this is
typically done is to create a container backed by a regular directory,
then create a new container which mounts the first container's rootfs
as a read-only lower mount, with a new private delta directory as
its read-write upper mount.  For instance, you could

	sudo lxc-create -t ubuntu -n r0 # create a normal directory
	sudo lxc-clone -B overlayfs -s r0 o1 # create overlayfs clone

The second container, o1, when started up will mount /var/lib/lxc/o1/delta0
as a writeably overlay on top of /var/lib/lxc/r0/rootfs, and use that as its
root filesystem.

From here you can clone o1 to a new container o2.  This simply copies the
the overlayfs delta from o1 to o2, and you is done with

	sudo lxc-clone -s o1 o2

LXC-SNAP

One of the obvious use cases of these snapshot clones is to support
incremental development of rootfs images.  Make some changes, snapshot,
make some more changes, snapshot, revert...

lxc-snap is a small program using the lxc API to more easily support
this use case.  You begin with a overlayfs backed container, make some
changes, snapshot, make some changes, snapshot...  This is a simpler
model than manually using clone because you continue developing the same
container, o1, while the snapshots are kept away until you need them.

EXAMPLE

Create your first container

	sudo lxc-create -t ubuntu -n base
	sudo lxc-clone -s -B overlayfs base mysql

Now make initial customizations, and snapshot:

	sudo lxc-snap mysql

This will create a snapshot container /var/lib/lxc/snapshots/mysql_0.  You can actually
start it up if you like using 'sudo lxc-start -P /var/lib/snapshots -n mysql_0'.
(However, that is not recommended, as it will cause changes in the rootfs)

Next, make some more changes.  Write a comment about the changes you made in this
version,

echo "Initial definition of table doomahicky" > /tmp/comment

	sudo lxc-snap -c /tmp/comment mysql

Do this a few times.  Now you realize you lost something you needed.  You can
see the list of containers which have snapshots using

	lxc-snap -l

and the list of versions of container mysql using

	lxc-snap -l mysql


Note that it shows you the time when the snapshot was created, and any comments
you logged with the snapshot.  You see that what you wanted was version 2, so
recover that snapshot.  You can destroy container mysql and restore version 2
to it, or (I would recommend) use a different name to restore the snapshot to.

Use a different name with:

	sudo lxc-snap -r mysql_2 mysql_tmp

or destroy mysql and restore the snapshot to it using

	sudo lxc-destroy -n mysql
	sudo lxc-snap -r mysql_2 mysql

When you'd like to export a container, you can clone it back to a directory
backed container and tar it up:

	sudo lxc-clone -B dir mysql mysql_ship
	sudo tar zcf /srv/mysql_ship.tar.gz /var/lib/lxc/mysql_ship

BUILD AND INSTALL

To use lxc-snap, you currently need to be using lxc from the ubuntu-lxc
daily ppa.  On an ubuntu system (at least 12.04) you can

	sudo add-apt-repository ppa:ubuntu-lxc/daily
	sudo apt-get update
	sudo apt-get dist-upgrade
	sudo apt-get install lxc-dev

lxc-snap will either become a part of the lxc package, or will become a
separate package.  Currently it is available at
git://github.com/hallyn/lxc-snap.  Fetch it using:

	git clone git://github.com/hallyn/lxc-snap

Then build lxc-snap by typing 'make'.

	cd lxc-snap
	make

Install into /usr/bin by typing

	sudo DESTDIR=/usr make install

or install into /home/$USER/bin by typing

	mkdir /home/$USER/bin
	DESTDIR=/home/$USER make install

Note that lxc-snap is in very early development, and its usage may
change over time.  Using a package (as soon as it becomes available)
is recommended.

NOTES ON OVERLAYFS

Overlayfs appears to have a limit of 10G.  This can be limiting
depending on the rootfs which you are developing.

NOTES ON LVM

LVM does not support snapshots of snapshots.  Therefore when restoring a
LVM snapshot, it is restored using a copy clone, which copies the whole

About

Small program to snapshot containers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages