public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Kashyap Chamarthy <kchamart@redhat.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: "Anders Östling" <anders.ostling@gmail.com>,
	kvm@vger.kernel.org, libvir-list@redhat.com,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
	"John Snow" <jsnow@redhat.com>, "Eric Blake" <eblake@redhat.com>,
	qemu-block@nongnu.org
Subject: Re: Backup of vm disk images
Date: Mon, 4 May 2020 11:51:57 +0200	[thread overview]
Message-ID: <20200504095157.GJ25680@paraplu> (raw)
In-Reply-To: <20200501150547.GA221440@stefanha-x1.localdomain>

On Fri, May 01, 2020 at 04:05:47PM +0100, Stefan Hajnoczi wrote:
> On Wed, Apr 22, 2020 at 07:51:09AM +0200, Anders Östling wrote:

Hi Anders,

> > I am fighting to understand the difference between backing up a VM by
> > using a regular copy vs using the virsh blockcopy command.

tl;dr: While 'blockcopy' is one way to do a full backup; there's a
       better way: 'blockcommit'; see below for a URL to an example.

To add to what Stefan says below, here's the difference: a regular 'cp'
is just that — an offline copy when your guest is shutdown or suspended.
However, libvirt's 'blockcopy' lets you create a "point-in-time snapshot
[or copy]" of your VM's disk _while_ the VM is running, and optionally,
lets your VM to "live-pivot" its storage to the just-created copy.

The use-case is "live storage migration".  

Say, your original storage of your VM is on NFS-A, but you want to do
some maintenance on NFS-A.  Here, 'blockcopy' lets you live-copy the
VM's storage from NFS-A to NFS-B, _and_ make the VM use the copy — all
this without causing any downtime to the users of the VM.  Now you can
freely do the maintenance on NFS-A.

A 'blockcopy' operation has two phases:

(1) It copies a VM's disk image, e.g. from 'orig.raw' to 'copy.qcow2',
    while the VM is running.  And it will _keep_ copying as long as your
    VM keeps writing new data.  This is called the "mirroring" phase.

(2) Once the copy.qcow2 has the same content as orig.raw, then you can
    do two things, either (a) end the copying/mirroring, which results
    in a point-in-time 'snapshot' of the orig.raw; or (b) you can
    "live-pivot" the VM's disk image to just-created copy.qcow2.

Management tools like OpenStack (and possibly others) use libvirt's
'blockcopy' API under the hood to allow live storage migration.

There are other useful details here, but I'll skip them for brevity.
Read the "blockcopy" section in `man virsh`.  I admit it can be a little
hard to parse when you normally don't dwell on these matters, but taking
time to experiement gives a robust understanding.

> > What I want to do is to suspend the vm, copy the XML and .QCOW2 files
> > and then resume the vm again. What are your thoughts? What are the
> > drawbacks compared to other methods?

If your main goal is to take a full backup of your disk, *without* any
downtime to your VM, libvirt does provide some neat ways.

One of the most efficient methods to is the so-called "active
block-commit".  It uses a combination of libvirt commands: `virsh
snapshot-create-as`, `virsh blockcommit`, and `rsync`:
   
I've written up a full example here:

    https://wiki.libvirt.org/page/Live-disk-backup-with-active-blockcommit

You might also want to refer to this page.

    https://wiki.libvirt.org/page/Live-disk-backup-with-active-blockcommit

            - - -

For libvirt-based incremental backup examples, I'll defer that to Eric
Blake (in Cc).

[...]

> A naive cp(1) command will be very slow because the entire disk image is
> copied to a new file.  The fastest solution with cp(1) is the --reflink
> flag which basically takes a snapshot of the file and shares the disk
> blocks (only available when the host file system supports it and not
> available across mounts).
> 
> Libvirt's backup commands are more powerful.  They can do things like
> copy out a point-in-time snapshot of the disk while the guest is
> running.  They also support incremental backup so you don't need to
> store a full copy of the disk image each time you take a backup.
> 
> I hope others will join the discussion and give examples of some of the
> available features.


-- 
/kashyap


      parent reply	other threads:[~2020-05-04  9:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-22  5:51 Backup of vm disk images Anders Östling
2020-05-01 15:05 ` Stefan Hajnoczi
2020-05-04  7:58   ` Peter Krempa
2020-05-05 15:01     ` Anders Östling
2020-05-04  9:51   ` Kashyap Chamarthy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200504095157.GJ25680@paraplu \
    --to=kchamart@redhat.com \
    --cc=anders.ostling@gmail.com \
    --cc=eblake@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=libvir-list@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=stefanha@gmail.com \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox