Backup/Move LXC Container

  1. Stop lxc container
    $ sudo lxc-stop -n <container>
  2. Archive lxc container. DON’T forget the option ‘–numeric-owner’. The ‘–numeric-owner’ flag is very important! Without it, the container may not boot because the uid/gids get mangled in the extracted filesystem

    $ sudo - su
    $ cd /var/lib/lxc/<container>/
    $ tar --numeric-owner -czvf container_fs.tar.gz ./*
  3. Copy the archive file to another server (ftp, sftp, or scp)
  4. Extract files on the new server
    $ sudo su -
    $ mkdir /var/lib/lxc/<container>/
    $ cd /var/lib/lxc/<container>/
    $ tar --numeric-owner -xzvf container_fs.tar.gz