Moving a container from an LXC 5 to an LXC 4 instance
It is not possible to transfer a container from a LXD 5 to an LXD 4 host with the regular
lxc copy function, because LXD 5 introduced some new metadata keys that LXD 4 rejects.
Instead, create a backup tarball of the container you want to transfer:
lxc export containername --compression none
Compression is disabled because editing a tarball is only possible when it is not compressed.
Next, move the tarball to the target LXD 4 host.
The offending metadata keys are contained in the tarball as yaml files. The tarball will typically contain all the snapshots associated with the container, each might hold very similar metadata. You need to make sure to remove the offending metadata keys from every configuration file.
Extract the metadata yaml files from the tarball:
tar xvf containername.tar --wildcards '*/index.yaml' '*/backup.yaml'
This will create a new directory tree called
backup. Examine all
yaml files contained therein and remove lines with the following keys:
There might be more incompatible keys, these are the 3 I found during my tests with a handful of containers.
When you’re done with the edits, append the metadata files to the tarball:
tar rf containername.tar --owner root --group root backup
Now the tarball is ready to import:
lxc import containername.tar
Should you get an error message like
Error: Failed importing backup: Failed creating instance record: Unknown configuration key: some.metadata.key
you can remove this key from all
yaml files and update the tarball again. Perhaps leave a comment here if you discover a new incompatible key.