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:
- 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
- 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
- To list the snapshots of a container, use the
lxc info
command and look for the “Snapshots” section.
lxc info mycontainer
- 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
- 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.