How to create snapshots with lxc command for LXD

last updated in Categories , ,

I need to save the state of my existing app running on LXD before I push new Python-based app. How do I create snapshots with lxc command for LXD based Linux container?

Introduction – LXD Linux system container manager. It gives a user experience comparable to virtual machines but using Linux containers instead. There is no VM like overheads. This page shows how to make snapshots with LXD and restore them if the need arises.

Procedure to create snapshots with lxc for LXD

  1. To make a snapshot for LXD, run: lxc snapshot containerName
  2. Create a snapshot named backup01 for Linux container named www1 using the lxc command: lxc snapshot www1 backup01
  3. Restore LXD container named www2 from snapshots named snap2, on Linux: lxc restore www2 snap2

Let us see examples and usage in derails.

How to create the LXD snapshot using lxc

The syntax is:
lxc snapshot {container} {snapshot-name}
Next, create the LXD snapshot:
$ lxc snapshot utls-newsletter snap-04-jan-2019
Verify snapsots or see info about snapshots:
$ lxc info utls-newsletter

Linux create snapshots with lxc command for LXD
Linux create snapshots with lxc command for LXD

Usually, I stop container before taking snapshots:
lxc stop www42
lxc snapshot www42 snap01
lxc start www42

How to restore the LXD snapshot using lxc

The syntax is:
lxc restore {container} {snapshot-name}
Restore the LXD snapshot:
lxc restore www42 snap01

How to delete the LXD snapshot using lxc command

Again the syntax is:
lxc delete {container}/snapshot-name}
To force user confirmation pass the -i option:
lxc delete {container}/snapshot-name} -i
Say you want to delete the LXD snapshot named snap-04-jan-2019 for utls-newsletter container, run:
$ lxc delete utls-newsletter/snap-04-jan-2019 -i
OR
$ lxc delete utls-newsletter/snap-04-jan-2019

Linux delete the LXD snapshot using lxc command
Linux delete the LXD snapshot using lxc command

Conclusion

Use the following commands to create, delete and restore snapshots for the LXD running on Linux.

lxc commandDescription for LXDExample(s)
lxc snapshot {container} {snapshot}Create a snapshotlxc snapshot www-c1 snap01
lxc restore {container} {snapshot}Restore the snapshotlxc restore www-c1 snap01
lxc info {container}Get the container information including snapshot infolxc www-c1
lxc delete {container}/{snapshot}Delete the snapshotlxc delete www-c1/snap01
This entry is 14 of 14 in the LXD Tutorial series. Keep reading the rest of the series:
  1. How to install LXD container hypervisor on Ubuntu 16.04 LTS
  2. How to install and setup LXC (Linux Container) on Fedora Linux 26
  3. How to install LXD container under KVM or Xen virtual machine
  4. How to list VM images in LXD (Linux Containers)
  5. How to upgrade LXD VMs powered by Ubuntu/Debian or CentOS Linux
  6. How to auto start LXD containers at boot time in Linux
  7. How to rename LXD / LXC container
  8. How to run commands on Linux Container (LXD) instance at provision launch time
  9. How to use LXD (Linux containers) in a shell script to create VM when the cloud instance launches
  10. How to move/migrate LXD VM to another host on Linux
  11. How to install and setup LXD on Fedora Linux server
  12. How to install and setup LXD on CentOS Linux 7.x server
  13. Install LXD pure-container hypervisor on Ubuntu 18.04 LTS
  14. Create snapshots with lxc command for LXD

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at www.nixcraft.com

Historical Comment Archive