How to create snapshots with lxc command for LXD

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

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
$ lxc delete utls-newsletter/snap-04-jan-2019

Linux delete the LXD snapshot using lxc command


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

lxc command Description for LXD Example(s)
lxc snapshot {container} {snapshot} Create a snapshot lxc snapshot www-c1 snap01
lxc restore {container} {snapshot} Restore the snapshot lxc restore www-c1 snap01
lxc info {container} Get the container information including snapshot info lxc www-c1
lxc delete {container}/{snapshot} Delete the snapshot lxc delete www-c1/snap01

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

Comments on this entry are closed.

Comments are closed. Still have questions? Post it on our forum