Skip to content

Instantly share code, notes, and snippets.

@ehrenfeu
Last active April 19, 2022 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehrenfeu/1fdcde22bfd505d8084f8f9b6739a46d to your computer and use it in GitHub Desktop.
Save ehrenfeu/1fdcde22bfd505d8084f8f9b6739a46d to your computer and use it in GitHub Desktop.
Backup up LXC containers using `tar`

Creating tarballs from LXC containers

NOTE: this is about tarring up plain LXC (i.e. not LXD) containers without the benefits of btrfs or similar

shut down the respective container, e.g.

lxc-stop mycontainer

ensure nothing "else" is (bind-) mounted into your container, e.g.

findmnt --real | grep mycontainer

otherwise unmount it, e.g.

sudo umount /scratch/containers/mycontainer/rootfs/var/backups/mycontainer

cd into the container's LXC directory, and run tar asking for numeric ownership preservation:

cd /scratch/containers/mycontainer
sudo tar \
    --numeric-owner \
    --xz \
    -cvf \
    /scratch/data/backups/containers/mycontainer-$(date +%F).tar.xz \
    config \
    rootfs

finally start the container again after the tar command finishes (re-mounting the bind-mount from above):

sudo mount /scratch/containers/mycontainer/rootfs/var/backups/mycontainer
lxc-start mycontainer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment