canonical / lxd

Powerful system container and virtual machine manager
https://canonical.com/lxd
GNU Affero General Public License v3.0
4.38k stars 931 forks source link

Import exported container as an image #5172

Closed melato closed 6 years ago

melato commented 6 years ago

Feature Request. Based on LXD 3.6

I would like to import an exported container as an image. It already contains all the files of an exported image but with a different path prefix.

Justification: A tarball created by exporting a container is very similar with a tarball created by exporting an image. I would like to be able to use them interchangeably, with either or both of the following enhancements:

The two different tarballs are currently created by:

export a container:

lxc export ${container} ${export-dir}/${container}.tar.xz --container-only

export a container as an image:

lxc snapshot ${container} temp
lxc publish ${container}/temp --alias=${container}
lxc image export ${container} ${export-dir}/${container}
lxc image delete ${container}
lxc delete ${container}/temp

An image has the following file structure:

metadata.yaml
templates
templates/...
rootfs
rootfs/...

An exported container has the file structure:

backup/index.yaml
backup/container/backup.yaml
backup/container/metadata.yaml
backup/container/templates/
backup/container/templates/...
backup/container/rootfs/
backup/container/rootfs/...

Both can be used for backups. The container export is faster, because it can be exported and imported directly between the container and the disk tarball. But it is more restrictive, because it can be imported only in a very similar LXD setup. I'm not exactly sure where it can be imported, but I've run to at least three problems:

These are some errors, I've encountered while trying to import an exported container:

Error: Internal import request: The storage pool's "default" driver "dir" conflicts with the driver "zfs" recorded in the container's backup file Error: Internal import request: Failed to list ZFS snapshots: cannot open 'z/lxd/containers/pound': dataset does not exist Error: Internal import request: Create container: Requested profile 'prod0' doesn't exist

An image does not have these restrictions. It is therefore more versatile as a backup solution (except that it needs the profiles, and perhaps other configuration, which can be exported and imported separately).

stgraber commented 6 years ago

I expect we'll be keeping the two concepts separate and that addition to our backups will further drive them away from images.

Right now they differ in:

To import a backup as a valid image, LXD would need to:

Because it'd need to be recompressed and re-hashed, this would equate to doing lxc import + lxc publish, at which point you may as well just do that.

As for your questions, I suspect you were dealing with an optimized backup, or LXD thought it was an optimized backup anyway, in which case, binary ZFS data is part of the backup and so requires restoration on a ZFS pool running the same or more recent version of ZFS and because the various binary dumps refer to each another based on dataset name, requires the name be the same.

Closing this issue as we don't plan on the two concepts to become closer to each another, quite the opposite actually.