Skip to content

Instantly share code, notes, and snippets.

@johnarok
Created July 31, 2018 16:28
Show Gist options
  • Save johnarok/368a594fc7ed66046803770ec00f60c6 to your computer and use it in GitHub Desktop.
Save johnarok/368a594fc7ed66046803770ec00f60c6 to your computer and use it in GitHub Desktop.
lxc-export-import

Refer: https://discuss.linuxcontainers.org/t/backup-the-container-and-install-it-on-another-server/463/4

lxc publish CONTAINER_NAME/SNAPSHOT_NAME --alias my-export
lxc image export my-export .

This will create a new LXD image from your container and export it as a tarball in your current directory. You can then ship that tarball to your target host and do:

lxc image import TARBALL --alias my-export
lxc init my-export NEW-CONTAINER

or

To clone a container, you'd just do "lxc copy SOURCE DESTINATION", but that's on a single local LXD. In your case, it looks like you're trying to test your backup mechanism.

Say you have a container called "blah". For backup as an image tarball, you'd do:

    lxc snapshot blah backup
    lxc publish blah/backup --alias blah-backup
    lxc image export blah-backup .
    lxc image delete blah-backup

Which will get you a tarball in your current directory.

To restore and create a container from it, you can then do:

    lxc image import TARBALL-NAME --alias blah-backup
    lxc launch blah-backup some-container-name
    lxc image delete blah-backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment