How to backup and restore LXD containers

To backup a LXD container, you can use the “lxc publish” command. The basic syntax for this command is “lxc publish [container name] –alias [backup name]”. This will create a snapshot of the container and save it as a new image with the specified alias (or backup name).

For example, to create a backup of a container named “mycontainer” with the backup name “mycontainer-backup”, you would use the command:

lxc publish mycontainer --alias mycontainer-backup

To restore a LXD container from a backup, you can use the “lxc launch” command with the backup image as the source. The basic syntax for this command is “lxc launch [backup name] [container name]”.

For example, to restore the container “mycontainer” from the backup image “mycontainer-backup”, you would use the command:

lxc launch mycontainer-backup mycontainer

It’s important to keep in mind that this will create a new container with the name “mycontainer” and delete the old one, so if you want to keep it you should use different name.

Another way to backup and restore LXD containers is to use lxc export and lxc import commands. For example, to export a container named “mycontainer” to a file named “mycontainer.tar.gz”, you would use the command:

lxc export mycontainer --output mycontainer.tar.gz

To import a container from a file named “mycontainer.tar.gz” with the name “mycontainer”, you would use the command:

lxc import mycontainer.tar.gz --name mycontainer

It’s also important to note that when you use these commands, it will backup and restore not just the container but also the container’s filesystem and state as well.

Leave a Comment