lxc clone & snapshot

 

 

 


Clones

 

Clones are either snapshots or copies of another container

A snapshot exploits the underlying backing store's snapshotting ability to make a copy-on-write container referencing the first.

Snapshots of directory-packed containers are created using the overlay filesystem.

在 C1 -clone-> C2 情況

 * C1 should not be allowed to run

 * C1 a canonical base container, and to only use its snapshots.

i.e. Full copy

# -o, --orig orig # The name of the original container to clone

lxc-clone -o c1-dir -n c2-dir

i.e. snapshot

lxc-clone -s c1-lvm c2-lvm

# tar backup

lxc-clone -B dir s1 dir_ship

tar -zcf /var/lib/lxc/dir_ship.tgz /var/lib/lxc/dir_ship

# Restore snapshot

lxc-clone -s s1 s1-backup         # just to make sure

lxc-destroy -n s1

lxc-clone -s s1-backup s1

# btrfs 與 lvm 的 snapshot 比較

btrfs snapshot

It is metadata based, so destroying the base container simply does not delete any of the data in use by the snapshot container.

lvm snapshot

lvm will note that there are active snapshots of the base rootfs and prevent the base container from being destroyed.

you cannot snapshot a snapshot

# overlayfs clone

可以用 lxc-create 或 lxc-copy (snapshot clone) 建立 Container

* lxc-clone 將被 lxc-copy 取代

lxc-create

lxc-create -n C1 -t ubuntu -B overlayfs

ls /var/lib/lxc/C1

delta0        # 342M
rootfs         # 0 M

config

#lxc.rootfs = /var/lib/lxc/C1/rootfs
#lxc.rootfs.backend = dir
lxc.rootfs = overlayfs:/var/lib/lxc/C1/rootfs:/var/lib/lxc/C1/delta0
lxc.rootfs.backend = overlayfs

lxc-clone

# create an overlayfs snapshot of it

lxc-clone -o C1 -n C2 -B overlayfs -s

-s argument asks for a snapshot

-B specifies the backing store type for the new container

 * A snapshot clone C2 of a directory backed container C1 becomes an overlayfs backed container,

 * delta0 will store only the changes that has been made to the container

Config

lxc.rootfs = overlayfs:/var/lib/lxc/C1/rootfs:/var/lib/lxc/C2/delta0
lxc.rootfs.backend = overlayfs

 


lxc-snapshot

 

Snapshots are stored as snapshotted containers under the container's configuration path.

(所以 lvm 用不到此 snapshot 功能)

/var/lib/lxc/c1

first snapshot: /var/lib/lxc/c1/snaps/snap0

# create snapshot

lxc-snapshot -n c1

snapshot location

If your original container was /var/lib/lxc/c1, then the first snapshot will be

/var/lib/lxcsnaps/c1/snap0

 * 在 U16 上不支援 lvm 的 backend

# List (-L,--list)

lxc-snapshot -n c1 -L

# Comment ( -c )

echo "before installing apache2" > comment.txt

lxc-snapshot -n c1 -c comment.txt

# Show snapshot comments ( -C )

lxc-snapshot -n c1 -L -C

# Restore (-r,--restore snapshot-name)

lxc-snapshot -n c1 -r snap0

# Restore as "c1-snap0"

lxc-snapshot -n p1-lvm -r snap0 c1-snap0

# Remove snapshot (-d,--destroy snapshot-name)

If the named snapshot is ALL, then all snapshots will be destroyed.

 


 

 

 

Creative Commons license icon Creative Commons license icon