rinseaid Posted June 18, 2017 Share Posted June 18, 2017 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 Quote Link to comment
boxer74 Posted July 13, 2017 Share Posted July 13, 2017 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 Quote Link to comment
rinseaid Posted July 16, 2017 Author Share Posted July 16, 2017 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. Quote Link to comment
fluisterben Posted September 9, 2019 Share Posted September 9, 2019 Anyone of you care to make a functional stable plugin out of this script and this other script below? Quote Link to comment
testdasi Posted September 9, 2019 Share Posted September 9, 2019 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"? 🙄 Quote Link to comment
JonathanM Posted September 9, 2019 Share Posted September 9, 2019 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 [email protected] about your wishes. Quote Link to comment
testdasi Posted September 9, 2019 Share Posted September 9, 2019 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. Quote Link to comment
golli53 Posted September 9, 2019 Share Posted September 9, 2019 Do these snapshots work when passing through a GPU? I ask because virsh save doesn't work when this is the case. Quote Link to comment
Recommended Posts
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.