How to backup a running container?


(carlos ) #1

Hi
Is there a way to make a backup of a running LXC container?

Any help would be appreciated

Thanks


(Stéphane Graber) #2

You may be able to make a snapshot. If using LXC itself, use lxc-snapshot, if using LXD, use lxc snapshot. In both cases, it’ll depend on what your storage backend is.


(carlos ) #3

Hi Stephane

I am using LXC 3.0.0 and LXCFS 3.0.0 compiled from sources on an Ubuntu 16 server
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial

lxc-ls --version output is 3.0.0

i have a container named nagios434b, it has storage backend dir type
while it is running if i try to make a snapshot:

lxc-snapshot -n nagios434b

i obtain this message:

lxc-snapshot: nagios434b: lxccontainer.c: do_lxcapi_snapshot: 3934 Snapshot of directory-backed container requested.
lxc-snapshot: nagios434b: lxccontainer.c: do_lxcapi_snapshot: 3935 Making a copy-clone. If you do want snapshots, then
lxc-snapshot: nagios434b: lxccontainer.c: do_lxcapi_snapshot: 3936 please create overlay clone first, snapshot that
lxc-snapshot: nagios434b: lxccontainer.c: do_lxcapi_snapshot: 3937 and keep the original container pristine.
lxc-snapshot: nagios434b: lxccontainer.c: do_lxcapi_clone: 3588 error: Original container (nagios434b) is running
lxc-snapshot: nagios434b: lxccontainer.c: do_lxcapi_snapshot: 3942 clone of /usr/local/var/lib/lxc:nagios434b failed

what do i have to do in order to make a backup of my container while it is running?

how can i make an overlay clone of my container?

I also tried to do the same with container of type lvm and overlay and it doesn’t work either.

PS: i am french , do you speak french?

Carlos


(Oliver) #4

Carlos, AFAIK you cannot do this because you use the directory backing store as evidenced by:

lxc-snapshot: nagios434b: lxccontainer.c: do_lxcapi_snapshot: 3934 Snapshot of directory-backed container requested.

I don’t know if LVM is supposed to be supported, but having used btrfs and zfs, I don’t remember such problems. Have you tried either of these? I think the underlying issue is tied to the fact that you need support from the backing store to have a snapshot operation that is atomic.


(Stéphane Graber) #5

@brauner do you remember how that stuff works? I must admit I’ve not used lxc-snapshot in years :slight_smile:


(Christian Brauner) #6

Ah right, we’ve never allowed snapshotting running containers afaik. But we could change that.


(carlos ) #7

Hi Christian

In fact what i need is to make a backup of a container without stopping it.

I have tried several backing store (dir, lvm, overlay and btrfs) and serveral tools lxc-snapshot, lxc-lxc-copy
and i still can’t backup a running container

Is there a way to do it?


(Ron Kelley) #8

For what its worth, we do a BTRFS snapshot each night on all our running containers (LXD 2.19). Some very quick pseudo-code:

#!/bin/bash
BTRFS_SNAPDIR="/var/lib/lxd/.nightly_snaps"
CONTAINER_BASE_DIR="/var/lib/lxd/containers"
RUNNINGVMS=$(lxc list --fast |grep RUNNING | awk '{print $2}' ) 

for container in $RUNNINGVMS; do     
 btrfs sub snap ${CONTAINER_BASE_DIR}/${container} ${BTRFS_SNAPDIR}/${DATE}__${container}__${LOCAL_IP}
[ $? -ne 0 ] && echo Snap failed for ${CONTAINER_BASE_DIR}/${container} && continue;
done

Note: This won’t quiesce any apps inside the container, and you will still have to copy the snapshot directory to a real backup server. Still, this is a great way to create an instant snapshot of a running container.


(carlos ) #9

Hi

but can you do that with: LXC 3.0.0 and LXCFS 3.0.0 compiled from sources on an Ubuntu 16 server?


(carlos ) #10

HI

How do you restore the backup created by btrfs sub snap ?

Thanks in advance