I want to take lxc container backup. We have server with 12.04 LTS ubuntu server and I have installed LXC - 1.0.0.alpha2 in it. I wanted to update our
To backup an lxc container quickly to a remote host without a btrfs filesystem I mount a filesystem from the remote host with sshfs & cd into the mount. Stop the container & create a tar.xz archive of it.
I now run my lxc containers on a btrfs filesystem to make it simpler to take a snapshot of the running containers. btrfs sub snap detects proc run sys are virtual filesystems & does not include them in the snapshot.
I use Duply to backup LXC containers. Unlike backing up a normal machine you DO want to include /dev from the LXC container in the backup.
apt-get install duply
duply mybackup create
In ~/.duply/mybackup/exclude I used:
- /cdrom
- /dev
- /lost+found
- /media
- /mnt
- /proc
- /run
- /sys
- /tmp
- /var/backup/restore/*
- /var/backup/tmp/*
- /var/lib/lxc/*/rootfs/lost+found
- /var/lib/lxc/*/rootfs/media/*
- /var/lib/lxc/*/rootfs/mnt/*
- /var/lib/lxc/*/rootfs/proc/*
- /var/lib/lxc/*/rootfs/run/*
- /var/lib/lxc/*/rootfs/sys/*
- /var/lib/lxc/*/rootfs/tmp/*
- /var/lib/lxcfs/*
The above will backup the whole machine & all the LXC containers.
To just backup containers edit ~/.duply/mybackup/conf & change SOURCE='/' to SOURCE='/var/lib/lxc' & remove the non lxc lines from ~/.duply/mybackup/exclude
Tested with running Alpine Linux LXC containers - will also work on Debian.
Simple Backups with Duply - you can also just do very simple unencrypted backups to a local file (set TARGET='file://[relative|/absolute]/local/path' in ~/.duply/mybackup/conf)
To sign Duply backups see GnuPG in Automated Environments ( password-less signing key instead of storing the password in plaintext ).
Set GPG_TEST='disabled' in the Duply conf file for cron jobs.
If you do not store any plaintext passwords in your conf do not disable GPG_TEST on restores - so gpg-agent caches your passwords.