How to use virsh to create snapshots for Debian 11

In this article, I'd like to discuss how to use virsh to create snapshots for a Debian 11 VM created with KVM or WebConsole.

Contents

  1. How to use virsh to create snapshots for Debian 11
    1. Syntax
      1. snapshot-create
      2. snapshot-list
      3. snapshot-info
      4. snapshot-revert
      5. snapshot-delete

Syntax

Let's take a look at syntax for available snapshot commands with virsh

$ virsh help | grep snapshot-
 snapshot-create Create a snapshot from XML
 snapshot-create-as Create a snapshot from a set of args
 snapshot-current Get or set the current snapshot
 snapshot-delete Delete a domain snapshot
 snapshot-dumpxml Dump XML for a domain snapshot
 snapshot-edit edit XML for a snapshot
 snapshot-info snapshot information
 snapshot-list List snapshots for a domain
 snapshot-parent Get the name of the parent of a snapshot
 snapshot-revert Revert a domain to a snapshot

snapshot-create

I recommend using snapshot-create-as which allows me to specify --name (name of snapshot), --description (some note for myself)

Here is Debian 11 vm I created earlier.

$ virsh list | egrep 'Name|d11vm'
 Id Name State
 21 d11vm running

To create our first snapshot from d11vm:

$ virsh snapshot-create-as d11vm --name d11snap01 --description "First Snapshot"
Domain snapshot d11snap01 created

I used d11snap01 for the name of snapshot and some note for myself.

snapshot-list

To see a list of snapshots from our d11vm:

$ virsh snapshot-list d11vm
 Name Creation Time State
--------------------------------------------------
 d11snap01 2021年08月22日 16:59:32 -0700 running

snapshot-info

To see more information on snapshot we're just created:

$ virsh snapshot-info d11vm --snapshotname d11snap01
Name: d11snap01
Domain: d11vm
Current: yes
State: running
Location: internal
Parent: -
Children: 0
Descendants: 0
Metadata: yes

Did you notice that there is no description in the info? Well, I had to use following command to see the description

$ virsh snapshot-dumpxml d11vm --snapshotname d11snap01 | grep description
 <description>First Snapshot</description>

Now, let's make some changes on our vm (d11vm) then roll-back (revert) to our first snapshot

How about we install "curl" in the vm (d11vm) ?

$ ssh d11vm
...
$ sudo apt update && sudo apt -y install curl
...
$ which curl
/usr/bin/curl

snapshot-revert

To rollback (revert) our vm (d11vm) to our first snapshot (d11snap01):

$ virsh snapshot-revert d11vm --snapshotname d11snap01

I did not see any message but we can check by log back into the vm (d11vm) and check if curl is installed.

$ ssh d11vm
...
$ which curl
(nothing)

That's what we expected. So roll-back (revert) was success!

snapshot-delete

So how do we delete a snapshot? Well, let's make another snapshot (d11snap02) before we delete one.

$ virsh snapshot-create-as d11vm --name d11snap02 --description "2nd Snapshot"
Domain snapshot d11snap02 created

$ virsh snapshot-list d11vm
 Name Creation Time State
--------------------------------------------------
 d11snap01 2021年08月22日 16:59:32 -0700 running
 d11snap02 2021年08月22日 17:17:51 -0700 running

To delete the 2nd snapshot (d11snap02):

$ virsh snapshot-delete d11vm --snapshotname d11snap02
Domain snapshot d11snap02 deleted

$ virsh snapshot-list d11vm
 Name Creation Time State
--------------------------------------------------
 d11snap01 2021年08月22日 16:59:32 -0700 running

That's it! I hope this was useful introduction to virsh snapshot commands.


CategoryVirtualization | CategorySystemAdministration

AltStyle によって変換されたページ (->オリジナル) /