Jump to content
rinseaid

KVM backup script using snapshots/blockcommit

8 posts in this topic Last Reply

Recommended Posts

I've been looking for a KVM backup script leveraging libvirt's snapshot and blockcommit features. The advantage of this method is that there is no downtime when taking backups, and they should also be application consistent. I've adapted the script found here (https://gist.github.com/cabal95/e36c06e716d3328b512b) for use with unRAID, to add additional functionality, and to fix some bugs.

 

The script will either back up specified VMs, or all using the '--all' parameter. VMs with spaces in their names are supported, and if specifying the VMs as a parameter, use double quotes around the VM name. VMs have to be running in order to take a snapshot, so the script will power up any VMs that are turned off, and will then attempt a clean shutdown once the snapshot has been committed and disks copied. There are global variables that you can modify in the script to specify how long to wait for a VM to start before aborting the backup process, and how long to wait for a VM to cleanly shut down before powering it off. CD-ROM images and floppy drive images (I mean...if you have any...?) are automatically excluded from the backup.

 

The script will utilize unRAID's built in notification system - which you can figure to send emails with a detailed summary that looks like this:

 



Event: unRAID Status
Subject: KVM Backup completed with warnings
Description: KVM Backup completed with warnings at 06/16/2017 03:31:33
Importance: warning

Total backup size: 845GB
Total backup duration:  00:31:32


Test-VM backup size: 171GB
Test-VM backup duration: 00:04:38

Test-VM2 backup size: 606GB
Test-VM2 backup duration: 00:21:55

Windows Server 2012 backup size: 29GB
Windows Server 2012 backup duration: 00:01:28

Windows Server 2016 Template backup size: 41GB
Windows Server 2016 Template backup duration: 00:03:31


06/16/2017 03:00:01 Beginning backup for Test-VM
06/16/2017 03:04:39 Test-VM backup size: 171GB
06/16/2017 03:04:39 Test-VM backup duration: 00:04:38
06/16/2017 03:04:39 Finished backup of Test-VM
06/16/2017 03:04:39 Starting Test-VM2 to begin backup process
06/16/2017 03:05:16 Waiting for Test-VM2 to start
06/16/2017 03:05:16 Beginning backup for Test-VM2
06/16/2017 03:26:23 Waiting for Test-VM2 to shut down.
06/16/2017 03:26:34 Shut down of Test-VM2 completed
06/16/2017 03:26:34 Test-VM2 backup size: 606GB
06/16/2017 03:26:34 Test-VM2 backup duration: 00:21:55
06/16/2017 03:26:34 Finished backup of Test-VM2
06/16/2017 03:26:34 Starting Windows Server 2012 to begin backup process
06/16/2017 03:26:34 Waiting for Windows Server 2012 to start
06/16/2017 03:26:34 Beginning backup for Windows Server 2012
06/16/2017 03:27:52 Waiting for Windows Server 2012 to shut down.
06/16/2017 03:28:02 Shut down of Windows Server 2012 completed
06/16/2017 03:28:02 Windows Server 2012 backup size: 29GB
06/16/2017 03:28:02 Windows Server 2012 backup duration: 00:01:28
06/16/2017 03:28:02 Finished backup of Windows Server 2012
06/16/2017 03:28:02 Starting Windows Server 2016 Template to begin backup process
06/16/2017 03:28:02 Waiting for Windows Server 2016 Template to start
06/16/2017 03:28:02 Beginning backup for Windows Server 2016 Template
06/16/2017 03:29:33 Waiting for Windows Server 2016 Template to shut down............
06/16/2017 03:31:33 Warning: Windows Server 2016 Template did not shut down within 120 seconds - forcing shutdown
06/16/2017 03:31:33 Shut down of Windows Server 2016 Template completed
06/16/2017 03:31:33 Windows Server 2016 Template backup size: 41GB
06/16/2017 03:31:33 Windows Server 2016 Template backup duration: 00:03:31
06/16/2017 03:31:33 Finished backup of Windows Server 2016 Template

 

Usage:

vm-snapshot.sh <backup folder> <list of domains, comma separated, or --all to backup all domains> [max-backups (default is 7 if not specified)]

 

The script can be found on github: https://github.com/rinseaid/unraid-vm-snapshot

Share this post


Link to post

This looks great. Are the snapshots incremental? Anybody using this? Any way to set dated backup file names or allow you to set a tag in the filename like "install" or something?

Sent from my Pixel using Tapatalk

Share this post


Link to post

The snapshots are not incremental, and unfortunately I'm not sure I have the time to implement this. As far as time stamps - a folder is created within your chosen destination with the name of the VM, and within that folder are time stamped folders that contain the VM backup files. There is no way to tag the filenames. I'll admit this is pretty quick and dirty and I'm hoping some form of backup is built into unRAID in the future.

Share this post


Link to post
1 hour ago, fluisterben said:

Anyone of you care to make a functional stable plugin out of this script and this other script below?

What happened to "ask NICELY"? 🙄

Share this post


Link to post
11 minutes ago, fluisterben said:

some people paid good money for Unraid.

Nobody that participated in this thread is paid to program plugins for unraid. It's all volunteer.

 

If you want to flex the "I paid for this product", please talk to support@limetech.com about your wishes.

Share this post


Link to post
18 minutes ago, fluisterben said:

Was that not nice enough? Wow. Seems to me your toes are a little too long. By the way, some people paid good money for Unraid.

My toes are indeed quite long.

Share this post


Link to post

Do these snapshots work when passing through a GPU? I ask because virsh save doesn't work when this is the case.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.