Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz KVM Forum 2016 Part...

53
Backups (and snapshots) with QEMU Max Reitz <[email protected]> KVM Forum 2016

Transcript of Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz KVM Forum 2016 Part...

Page 1: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Backups (and snapshots) with QEMU

Max Reitz <[email protected]>

KVM Forum 2016

Page 2: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Part I

Kinds of backups

Or: Yes, snapshots are backups, too

Page 3: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Real backups

Page 4: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Real backups with QEMU

Page 5: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Not-so-real backups (snapshots)

Page 6: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Not-so-real backups (snapshots)

SnapshotOverlay

I/O Read

missing data

Page 7: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Not-so-real backups (snapshots)

SnapshotOverlay

I/O Read

missing data

Page 8: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Not-so-real backups (snapshots)

BottomTop

I/O

Page 9: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Snapshots with QEMU

Partially

allocated

Backing

image

Page 10: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Internal snapshots

Page 11: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Part II

How not to do backups

Or: Why this talk exists

Page 12: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

How it doesn’t work

Page 13: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Zooming in...

QEMU corrupts QCOW2 images

(Internal) snapshots taken with qemu-img

while the VM is running

Writing to a disk image from two processes maybreak it

Page 14: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Zooming in...

QEMU corrupts QCOW2 images

(Internal) snapshots taken with qemu-img

while the VM is running

Writing to a disk image from two processes maybreak it

Page 15: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Zooming in...

QEMU corrupts QCOW2 images

(Internal) snapshots taken with qemu-img

while the VM is running

Writing to a disk image from two processes maybreak it

Page 16: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

What to do about this: Lock images

Page 17: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

What to do about this: Inform people

Page 18: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Part III

Creating backups

Page 19: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Section 1

Introduction to QMP

Page 20: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Introduction to QMP

QMP

Run-time management:

Pause, resume, ...

Add/remove devices

...and much more, see qmp-commands.txt

Try it: -qmp stdio

Page 21: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Introduction to QMP

QMP on the line

<- { "execute": "some-command",

"arguments": { "arg1": "value1" } }

-> { "return": {} }

-> { "error": { "class": "GenericError",

"desc": "..." } }

-> { "event": "SOME_EVENT",

"timestamp": { ... } }

Page 22: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Introduction to QMP

Example command execution

<- { "execute": "stop" }

-> { "timestamp": {

"seconds": 1467422834,

"microseconds": 157734 },

"event": "STOP" }

-> { "return": {} }

Page 23: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Introduction to QMP

Short command notation

{ "execute": "some-command",

"arguments": { "arg1": "value1" } }

=

some-command(arg1="value1")

Page 24: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Section 2

Creating snapshots

Page 25: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Creating snapshots

Internal snapshots

blockdev-snapshot-internal-sync

device: Name of the block device

name: Name of the new snapshot

Page 26: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Creating snapshots

Internal snapshots

blockdev-snapshot-internal-sync(

device="disk0", name="3"

)

Page 27: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Creating snapshots

Internal snapshots

blockdev-snapshot-internal-sync(

device="disk0", name="3"

)

Page 28: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Creating snapshots

External snapshots

blockdev-snapshot-sync

device: Name of the block device

snapshot-file: File name of the new overlayimage

format: Format of the new overlay image

(and more)

Page 29: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Creating snapshots

External snapshots

blockdev-snapshot-sync(device="disk0",

snapshot-file="foo.qcow2",

format="qcow2")

Page 30: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Creating snapshots

External snapshots

blockdev-snapshot-sync(device="disk0",

snapshot-file="foo.qcow2",

format="qcow2")

foo.qcow2

disk0

Page 31: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Section 3

Introduction to block jobs

Page 32: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Introduction to block jobs

What are block jobs?

Asynchronous operations in QEMU’s block layer

Controlled using QMP

Page 33: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Introduction to block jobs

How to use block jobs: QMP

<- $BLOCK_JOB_NAME(job-id="foo", ...)

-> { "return": {} }

[Some time passes...]

-> { "event": "BLOCK_JOB_COMPLETED",

"data": { "device": "foo", ... } }

Page 34: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Introduction to block jobs

Block jobs with a “ready” phase

Page 35: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Introduction to block jobs

Block jobs with a “ready” phase: QMP

-> { "event": "BLOCK_JOB_READY",

"data": { "device": "foo", ... } }

<- block-job-complete(device="foo")

-> { "return": {} }

-> { "event": "BLOCK_JOB_COMPLETED",

"data": { "device": "foo", ... } }

Page 36: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Section 4

Copying off

Page 37: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Copying off

drive-backup block job

Copies disk’s data (at the start of the job) toanother file

Stalls guest writes to areas not yet saved→ May slow the guest downArguments (excerpt):

device: Source virtual drivetarget: Target file namesync: What to copymode: Should the target file be created?

Page 38: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Copying off

sync=fullCopy everything

Backup

Page 39: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Copying off

sync=topCopy only the topmost overlay in the snapshot chain

Backup

Page 40: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Copying off

sync=incrementalCopy data that has changed from the last backup

See John’s and Vladimir’s talk from last year:

Incremental Backups

John Snow (yes, I know) Vladimir Sementsov-OgievskiySoftware Engineer, Red Hat Software Developer, Odin2015-08-20

(Good things come in small packages!)

Page 41: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Copying off

drive-mirror block job

Copies disk’s data (at the end of the job) toanother file

Essential for storage migration

Does not stall guest, but may copy the samearea repeatedlyHas a ready phase

block-job-complete: Attaches the target image tothe guest diskblock-job-cancel: Similar to drive-backup

No incremental sync mode

Page 42: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Part IV

Rolling back

Page 43: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Rolling back

Backups and external snapshots:

1 Switch off VM

2 Replace active image by the backup

Internal snapshots:

1 Switch off VM

2 Use qemu-img snapshot -a

Page 44: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Part V

Discarding backups

Page 45: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Internal snapshots

blockdev-snapshot-delete-internal-sync

device: Name of the block device

name: Name of the snapshot to be deleted

(and more)

Page 46: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

External snapshots: block-stream block job

base

Page 47: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

External snapshots: block-stream block job

Copies data from the snapshot to the overlay,then drops the snapshot from the backing chain

Arguments:

device: Name of the block device

base: File name of the topmost snapshot tokeep (none if not specified)

(and more)

Page 48: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

External snapshots: block-commit block job

basetop

Page 49: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

External snapshots: block-commit block job

Copies data from the overlay to the snapshot,then drops the overlay from the backing chain

Arguments:

device: Name of the block device

base: File name of the snapshot to write into

top: File name of the topmost overlay to drop(very topmost overlay if not specified)

(and more)

Page 50: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Backups

Stand-alone backups: Just delete the file

Incremental backups: qemu-img commit

Page 51: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Part VI

Which to use

Page 52: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Comparison

Int. Sn. Ext. Sn. BackupTake Rather quick(1) Quick Slow

Roll back Rather quick(1) Quick Slow

Discard Rather quick(1) Slow Depends(2)

Format -specific -specific -agnostic

Off-site No Not really Yes

(1) Requires quite a few metadata updates

(2) Quick for stand-alone; slow for incremental

Page 53: Backups (and snapshots) with QEMU...Backups (and snapshots) with QEMU Max Reitz  KVM Forum 2016 Part I Kinds of backups Or: Yes, snapshots are backups, too

Thank you for listening!

Questions?