How to create snapshots with lxc command for LXD

LXD, the LXC daemon, provides a simple and powerful command-line tool called lxc to manage Linux containers. With lxc, you can create, manage, and delete snapshots of your container.

Here are the steps to create a snapshot of a container named “mycontainer” using the lxc command:

  1. First, make sure the container is in a stopped state. If the container is running, use the lxc stop command to stop it.
lxc stop mycontainer
  1. Use the lxc snapshot command to create a snapshot of the container. The command takes the container name and a snapshot name as arguments.
lxc snapshot mycontainer mysnapshot
  1. To list the snapshots of a container, use the lxc info command and look for the “Snapshots” section.
lxc info mycontainer
  1. To restore a container to a specific snapshot, use the lxc restore command followed by the container name, the snapshot name and the target container name
lxc restore mycontainer/mysnapshot mynewcontainer
  1. To delete a snapshot, use the lxc delete command followed by the container name and the snapshot name
lxc delete mycontainer/mysnapshot

You can also create a snapshot with a timestamp attached to the name by adding --epoch option in the snapshot command, that way you can keep track of multiple snapshots made at different times.

lxc snapshot mycontainer mysnapshot --epoch

Note that creating snapshots of a running container is not recommended as it may result in inconsistent state. It is best to stop the container before creating a snapshot to ensure that the snapshot is a consistent state of the container.

Leave a Comment