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