Jump to content
danioj

unraid-autovmbackup: automate backup of virtual machines in unRAID - v0.4

224 posts in this topic Last Reply

Recommended Posts

1 minute ago, rorton said:

So do i need to change my type to something other than vmdk? or leave that, and just rename the file to have .img extension, and change the same in the source file path above?

The type of the vdisk stays the same. Simply change the file itself to librenms.img and the extension in the source file path to the same.

Share this post


Link to post

top job, worked perfectly thank you :) at least i can automate the backup of both vm's now - are the extensions interchangeable then? It was a disk image i grabbed from the librenms website so remember i had to do some converting with it. 

Share this post


Link to post

@rorton You can convert the formats sure.

 

example:

qemu-img convert -O qcow2 -p original_image.img changed_image.qcow2

or

qemu-img convert -O raw -p original_image.qcow2 changed_image.img

With the above cli command you can convert the "original" image to an qcow2 format. "-O" followed by the "input-file" and the "output-file". "-p" shows the progress of the convertion. Second example is to output an raw vdisk file. Every format has some extra options you can use. For example qcow2 supports compressed files (-c).

 

Here is a quick link for the qemu-img man page:

https://linux.die.net/man/1/qemu-img

 

If you're on the latest unraid 6.8 RC version you might avoid compressed qcow2 files right now. I've discovered a bug where the disk can get coruppted. Not actual sure if this a unraid or a qemu issue.

Share this post


Link to post

I know it's been a while, but I made some big-ish changes to the script that some of you may find useful. I haven't really read back through the thread yet, so I'm not sure if someone else has made any additions not included here.

 

The biggest changes are

1. vdisk extensions are pulled directly from the config file, so you can name them anything you want (except .snap). This should prevent the issue @rorton was having.

2. SNAPSHOTS!! Snapshots are now able to be used to allow live backups, but there are some caveats so be sure to pay attention to the notes in the script when enabling it. BIG thanks to @Dikkekop for that one.

3. any extension can be blacklisted now, not just iso.

 


v1.1.5 - 2019/11/21

In Loving Memory of Net Neutrality

 

- fixed some errors not generating an error log file.

- updated comments.

- updated documentation to include important information.

- reverse changelog order.

- added support for more vdisk extensions by parsing them directly from the config.

- added user variable (case-insensitive) for blacklisting extensions. iso included by default.

- fixed issue with where files would not be removed after compressing when config files were not set to be backed up.

- updated comments to use more consistent terms.

- added option to allow specific vms to be backed up without shutting down.

- added option to allow vms to be backed up using snapshots. disabled by default.

- fixed script trying to remove leftover files that weren't part of the backup.

 

This thing has gotten rather complex, and I only use some of the functions in my backups, so as always: I've tested it as best as I am able to, but cannot guarantee it will work for you. Please verify your backups are running correctly when using the script.

 

Script here: https://github.com/JTok/unraid-vmbackup/tree/v1.1.5

 

-JTok

Edited by JTok
forgot to include my undying gratitude
  • Like 1
  • Thanks 1

Share this post


Link to post

First of all, big big thanks for the updated Script. I use it without issues for a long time now. I appreciate your work for the community. It saved my ass a couple times.

 

But I have a quick questions. I never used the snapshot feature before

2 hours ago, JTok said:

2. SNAPSHOTS!! Snapshots are now able to be used to allow live backups, but there are some caveats so be sure to pay attention to the notes in the script when enabling it. BIG thanks to @Dikkekop for that one.

# use snapshots to backup vms.
# NOTE: vms that are backed up using snapshots will not be shutdown. if a vm is already shutdown the default backup method will be used.
# WARNING: this will fail if the config path for the virtual disk is /mnt/user/. you must use /mnt/cache/ or /mnt/diskX/ for snapshots to work.
use_snapshots="0"

The default path created by Unraid for the vdisk in the xml is /mnt/user/VMSHARE. I have to change every VM's xml config by hand to make the snapshot backups to work, am I right???

 

So for my example

<source file='/mnt/user/VMs/Win7_Outlook/WIN7_OUTLOOK.qcow2'/>

I have to change it to

<source file='/mnt/cache/VMs/Win7_Outlook/WIN7_OUTLOOK.qcow2'/>

for a VM on a cache drive or to /disk2 for example if the vdisk is sitting on disk 2 in the array.

 

 

Share this post


Link to post

@JTok I had the time now to test the new script. Unfortunatly it didn't worked with all my settings I used before. Snapshots are turned off and the following is shown in the error log.

2019-11-21 13:58 information: use_snapshots is 0. vms will not be backed up using snapshots.
.
.
2019-11-21 13:59 failure: unable to perform snapshot for disk /mnt/user/VMs/Mint/vdisk1.img on Mint. skipping backup for Mint to prevent data loss. no cleanup will be performed for this vm. use_snapshots is 0. vm_state is shut off. vdisk_type is qcow2.

VM is shutdown correctly, XML and vram is transferred to the destination and at the point where the vdisk should be copied, it errors out the script. VM isn't returned to it's original state but it's setup in the script to do so.

 

Full log:

2019-11-21 13:58  Start logging to log file.
2019-11-21 13:58 information: keep_log_file is 1. log files will be kept.
2019-11-21 13:58 information: number_of_log_files_to_keep is 12. this is probably a sufficient number of log files to keep.
2019-11-21 13:58 information: snap extension not found in vdisk_extensions_to_skip. extension was added.
2019-11-21 13:58 information: use_snapshots is 0. vms will not be backed up using snapshots.
2019-11-21 13:58 information: kill_vm_if_cant_shutdown is 1. vms will be forced to shutdown if a clean shutdown can not be detected.
2019-11-21 13:58 information: set_vm_to_original_state is 1. vms will be set to their original state after backup.
2019-11-21 13:58 information: number_of_days_to_keep_backups is 30. this is probably a sufficient number of days to keep your backups.
2019-11-21 13:58 information: number_of_backups_to_keep is 5. this is probably a sufficient number of backups to keep.
2019-11-21 13:58 information: compress_backups is 1. backups will be compressed.
2019-11-21 13:58 information: enable_reconstruct_write is 0. reconstruct write will not be enabled by this script.
2019-11-21 13:58 information: compare_files is 0. files will not be compared after backups.
2019-11-21 13:58 information: backup_xml is 1. vms will have their xml configurations backed up.
2019-11-21 13:58 information: backup_nvram is 1. vms will have their nvram backed up.
2019-11-21 13:58 information: backup_vdisks is 1. vms will have their vdisks backed up.
2019-11-21 13:58 information: start_vm_after_backup is 0. vms will not be started following successful backup.
2019-11-21 13:58 information: start_vm_after_failure is 0. vms will not be started following an unsuccessful backup.
2019-11-21 13:58 information: disable_delta_sync is 0. rsync will be used to perform delta sync backups.
2019-11-21 13:58 information: rsync_only is 0. cp will be used when applicable.
2019-11-21 13:58 information: actually_copy_files is 1. files will be copied.
2019-11-21 13:58 information: clean_shutdown_checks is 20. this is probably a sufficient number of shutdown checks.
2019-11-21 13:58 information: seconds_to_wait is 30. this is probably a sufficient number of seconds to wait between shutdown checks.
2019-11-21 13:58 information: keep_error_log_file is 1. error log files will be kept.
2019-11-21 13:58 information: number_of_error_log_files_to_keep is 12. this is probably a sufficient error number of log files to keep.
2019-11-21 13:58 information: started attempt to backup 
Mint
 to /mnt/user/Backup/vm_sicherung
2019-11-21 13:58 information: Mint can be found on the system. attempting backup.
2019-11-21 13:58 information: /mnt/user/Backup/vm_sicherung/Mint exists. continuing.
2019-11-21 13:58 information: skip_vm_shutdown is false. beginning vm shutdown procedure.
2019-11-21 13:58 action: Mint is running. shutting down.
2019-11-21 13:58 information: performing 20 30 second cycles waiting for Mint to shutdown cleanly
2019-11-21 13:58 information: cycle 1 of 20: waiting 30 seconds before checking if the vm has shutdown
2019-11-21 13:59 information: Mint is shut off. can_backup_vm set to y
2019-11-21 13:59 action: actually_copy_files is 1.
2019-11-21 13:59 action: can_backup_vm flag is y. starting backup of Mint configuration, nvram, and vdisk(s).
2019-11-21 13:59 information: backup of Mint xml configuration to /mnt/user/Backup/vm_sicherung/Mint/20191121_1358_Mint.xml complete.
2019-11-21 13:59 information: backup of Mint nvram to /mnt/user/Backup/vm_sicherung/Mint/20191121_1358_065a6081-e954-0913-370d-b6001262fb61_VARS-pure-efi.fd complete.
2019-11-21 13:59 failure: unable to perform snapshot for disk /mnt/user/VMs/Mint/vdisk1.img on Mint. skipping backup for Mint to prevent data loss. no cleanup will be performed for this vm. use_snapshots is 0. vm_state is shut off. vdisk_type is qcow2.
2019-11-21 13:59 information: finished attempt to backup 
Mint
 to /mnt/user/Backup/vm_sicherung.
2019-11-21 13:59 information: cleaning out logs over 12.
2019-11-21 13:59 information: removed '/mnt/user/Backup/vm_sicherung/logs/20190901_0630_unraid-vmbackup.log'
2019-11-21 13:59 information: cleaning out error logs over 12.
2019-11-21 13:59 information: did not find any error log files to remove.
2019-11-21 13:59 warning: errors found. creating error log file.
2019-11-21 13:59  Stop logging to error log file.

Full script with all my settings:

#!/bin/bash
#backgroundOnly=true
#arrayStarted=true
#noParity=true

# v1.1.5 - 2019/11/21

#### DISCLAIMER ####
# Use at your own risk. This is a work-in-progress and provided as is.
# I have tested this on my own server, as best as I am able, but YMMV.
# -jtok


# what is the scripts' official name.
official_script_name="script"

# set the name of the script to a variable so it can be used.
me=$(basename "$0")


# this script copies unRAID vm's vdisks and their configurations to a specified location.

################################################## script variables start ######################################################

# default 0 but set the master switch to 1 if you want to enable the script otherwise it will not run.
enabled="1"

# backup location to put vdisks.
backup_location="/mnt/user/Backup/vm_sicherung/"

# list of vms that will be backed up separated by a new line.
vms_to_backup="
Mint
"

# list of specific vdisks to be skipped. use the full path.
vdisks_to_skip="

"

# list of specific vdisk extensions to be skipped. this replaces the old ignore_isos variable.
vdisk_extensions_to_skip="
iso
"

# use snapshots to backup vms.
# NOTE: vms that are backed up using snapshots will not be shutdown. if a vm is already shutdown the default backup method will be used.
# WARNING: this will fail if the config path for the virtual disk is /mnt/user/. you must use /mnt/cache/ or /mnt/diskX/ for snapshots to work.
use_snapshots="0"

# default is 0. set this to 1 if you would like to kill a vm if it cant be shutdown cleanly.
kill_vm_if_cant_shutdown="1"

# default is 1. set this to 0 if you do not want a vm to be started if it was running before the backup started. Paused VMs will be left stopped.
set_vm_to_original_state="1"

# default is 0. set this to the number of days backups should be kept. 0 means indefinitely.
number_of_days_to_keep_backups="30"

# default is 0. set this to the number of backups that should be kept. 0 means infinitely.
# WARNING: If VM has multiple vdisks, then they must end in sequential numbers in order to be correctly backed up (i.e. vdisk1.img, vdisk2.img, etc.).
number_of_backups_to_keep="5"

# default is 0. set this to 1 if you would like to compress backups. This can add a significant amount of time to the backup process. uses tar.gz for sparse file compatibility.
# WARNING: do not turn on if you already have uncompressed backups. You will need to move or delete uncompressed backups before using. this will compress all config, nvram, and vdisk images in the backup directory into ONE tarball.
compress_backups="1"

# default is 1. set this to 0 if you would like to have backups without a timestamp. Timestamps are dropped only when number_of_backups_to_keep is equal to 1.
timestamp_files="1"


#### logging and notifications ####

# default is 1. set to 0 to have log file deleted after the backup has completed.
# NOTE: error logs are separate. settings for error logs can be found in the advanced variables.
keep_log_file="1"

# default is 1. number of successful log files to keep. 0 means infinitely.
number_of_log_files_to_keep="12"

# default is "logs". set to "" to put in root of backups folder. set to "logs/<subfolder>" to keep logs separate if running multiple versions of this script.
log_file_subfolder="logs"

# default is 1. set to 0 to prevent notification system from being used. Script failures that occur before logging can start, and before this variable is validated will still be sent.
send_notifications="1"

# default is 0. set to 1 to receive more detailed notifications. will not work with send_notifications disabled or only_send_error_notifications enabled.
detailed_notifications="0"


#### advanced variables ####

# list of vms that will be backed up WITHOUT first shutting down separated by a new line. These must also be listed in vms_to_backup.
# NOTE: vms backed up via snapshot will not be shutdown (see use_snapshots option).
# WARNING: using this setting can result in an unusable backup. not recommended.
vms_to_backup_running="
"

# default is 0. set to 1 to have reconstruct write (a.k.a. turbo write) enabled during the backup and then disabled after the backup completes.
# NOTE: may break auto functionality when it is implemented. do not use if reconstruct write is already enabled. backups may run faster with this enabled.
enable_reconstruct_write="0"

# default is 0. set this to 1 to compare files after copy and run rsync in the event of failure. could add significant amount of time depending on the size of vms.
compare_files="0"

# default is 1. set to 0 if you would like to skip backing up xml configuration files.
backup_xml="1"

# default is 1. set to 0 if you would like to skip backing up nvram files.
backup_nvram="1"

# default is 1. set to 0 if you would like to skip backing up vdisks. setting this to 0 will automatically disable compression.
backup_vdisks="1"

# default is 0. set this to 1 if you would like to start a vm after it has successfully been backed up. will override set_vm_to_original_state when set to 1.
start_vm_after_backup="0"

# default is 0. set this to 1 if you would like to start a vm after it has failed to have been backed up. will override set_vm_to_original_state when set to 1.
start_vm_after_failure="0"

# default is 0. set this to 1 to disable rsync delta syncs.
disable_delta_sync="0"

# default is 0. set this to 1 to use rsync instead of cp. 
# NOTE: rsync was significantly slower in my tests.
rsync_only="0"

# default is 1. set this to 0 if you would like to perform a dry-run backup. 
# WARNING: will not work unless rsync_only is set to 1. if this is set to 1 and rsync_only is set to 0, then backups will be partial and the script won't work correctly.
actually_copy_files="1"

# default is 20. set this to the number of times you would like to check if a clean shutdown of a vm has been successful.
clean_shutdown_checks="20"

# default is 30. set this to the number of seconds to wait in between checks to see if a clean shutdown has been successful.
seconds_to_wait="30"

# default is 1. set to 0 to have error log files deleted after the backup has completed.
keep_error_log_file="1"

# default is 10. number of error log files to keep. 0 means infinitely.
number_of_error_log_files_to_keep="12"

# default is 0. set to 1 to only send error notifications.
only_send_error_notifications="0"


################################################## script variables end #########################################################


###################################################### script start #############################################################


EDIT: removed the part bellow "script start" to not overload the page with code

Edited by bastl

Share this post


Link to post
5 hours ago, bastl said:

The default path created by Unraid for the vdisk in the xml is /mnt/user/VMSHARE. I have to change every VM's xml config by hand to make the snapshot backups to work, am I right???

 

So for my example


<source file='/mnt/user/VMs/Win7_Outlook/WIN7_OUTLOOK.qcow2'/>

I have to change it to


<source file='/mnt/cache/VMs/Win7_Outlook/WIN7_OUTLOOK.qcow2'/>

for a VM on a cache drive or to /disk2 for example if the vdisk is sitting on disk 2 in the array.

 

 

 

Yes, that is exactly how it works. :)

 

3 hours ago, bastl said:

@JTok I had the time now to test the new script. Unfortunatly it didn't worked with all my settings I used before. Snapshots are turned off and the following is shown in the error log.

VM is shutdown correctly, XML and vram is transferred to the destination and at the point where the vdisk should be copied, it errors out the script. VM isn't returned to it's original state but it's setup in the script to do so.

 

 

I was able to replicate your issue, and I'm working on it now. I'm hoping to have it fixed in the next few hours.

 

Share this post


Link to post

@bastl

 

I think I fixed it. Please grab the updated v1.1.5 script from the GitHub link I used earlier and let me know.

 

Thanks,

JTok

Share this post


Link to post

Thanks @JTok for the quick fix.

 

In my scenario the backup is created and compressed as it should be now. But there are a couple warnings when the script is running. Maybe it's something important for other setups. Not sure if the "namespace warning" has an impact on the xml if the script is run with snapshots. During testing the old script with snapshots turned on I noticed that the xml has been modified to add the "vdisk1.snap". Currently running 6.8 RC6. Maybe something has changed with the newer Qemu 4.1.1 version. I have used the exact same settings as posted before with the fixed script.

Mint.xml:5: namespace warning : xmlns: URI unraid is not absolute

The line 5 in the xml looks like the following in my VM:

    <vmtemplate xmlns="unraid" name="Debian" icon="linux-mint.png" os="debian"/>

Another "maybe" warning is at the end of the logs:

/tmp/user.scripts/tmpScripts/vm_sicherung/script: line 3301: [: : integer expression expected

In case I should test something or you need some more info, let me know!

 

Full log:

Script location: /tmp/user.scripts/tmpScripts/vm_sicherung/script
Note that closing this window will abort the execution of this script
2019-11-21 21:01 information: official_script_name is script. script name is valid. continuing.
2019-11-21 21:01 information: enabled is 1. script is enabled. continuing.
2019-11-21 21:01 information: backup_location is /mnt/user/Backup/vm_sicherung. this location exists. continuing.
2019-11-21 21:01 information: backup_location is /mnt/user/Backup/vm_sicherung. this location is writable. continuing.
2019-11-21 21:01 information: timestamp_files is 1. timestamp will be added to backup files.
2019-11-21 21:01 information: /mnt/user/Backup/vm_sicherung/logs/ exists. continuing.
2019-11-21 21:01 information: log_file_subfolder is /mnt/user/Backup/vm_sicherung/logs/. this location exists. continuing.
2019-11-21 21:01 information: log_file_subfolder is /mnt/user/Backup/vm_sicherung/logs/. this location is writable. continuing.
2019-11-21 21:01 Start logging to log file.
2019-11-21 21:01 information: send_notifications is 1. notifications will be sent.
2019-11-21 21:01 information: only_send_error_notifications is 0. normal notifications will be sent if send_notifications is enabled.
2019-11-21 21:01 information: keep_log_file is 1. log files will be kept.
2019-11-21 21:01 information: number_of_log_files_to_keep is 12. this is probably a sufficient number of log files to keep.
2019-11-21 21:01 information: snap extension not found in vdisk_extensions_to_skip. extension was added.
2019-11-21 21:01 information: use_snapshots is 0. vms will not be backed up using snapshots.
2019-11-21 21:01 information: kill_vm_if_cant_shutdown is 1. vms will be forced to shutdown if a clean shutdown can not be detected.
2019-11-21 21:01 information: set_vm_to_original_state is 1. vms will be set to their original state after backup.
2019-11-21 21:01 information: number_of_days_to_keep_backups is 30. this is probably a sufficient number of days to keep your backups.
2019-11-21 21:01 information: number_of_backups_to_keep is 5. this is probably a sufficient number of backups to keep.
2019-11-21 21:01 information: compress_backups is 1. backups will be compressed.
2019-11-21 21:01 information: enable_reconstruct_write is 0. reconstruct write will not be enabled by this script.
2019-11-21 21:01 information: compare_files is 0. files will not be compared after backups.
2019-11-21 21:01 information: backup_xml is 1. vms will have their xml configurations backed up.
2019-11-21 21:01 information: backup_nvram is 1. vms will have their nvram backed up.
2019-11-21 21:01 information: backup_vdisks is 1. vms will have their vdisks backed up.
2019-11-21 21:01 information: start_vm_after_backup is 0. vms will not be started following successful backup.
2019-11-21 21:01 information: start_vm_after_failure is 0. vms will not be started following an unsuccessful backup.
2019-11-21 21:01 information: disable_delta_sync is 0. rsync will be used to perform delta sync backups.
2019-11-21 21:01 information: rsync_only is 0. cp will be used when applicable.
2019-11-21 21:01 information: actually_copy_files is 1. files will be copied.
2019-11-21 21:01 information: clean_shutdown_checks is 20. this is probably a sufficient number of shutdown checks.
2019-11-21 21:01 information: seconds_to_wait is 30. this is probably a sufficient number of seconds to wait between shutdown checks.
2019-11-21 21:01 information: keep_error_log_file is 1. error log files will be kept.
2019-11-21 21:01 information: number_of_error_log_files_to_keep is 12. this is probably a sufficient error number of log files to keep.
2019-11-21 21:01 information: started attempt to backup
Mint
to /mnt/user/Backup/vm_sicherung
2019-11-21 21:01 information: Mint can be found on the system. attempting backup.
2019-11-21 21:01 information: /mnt/user/Backup/vm_sicherung/Mint exists. continuing.
Mint.xml:5: namespace warning : xmlns: URI unraid is not absolute

^
Mint.xml:5: namespace warning : xmlns: URI unraid is not absolute

^
2019-11-21 21:01 information: skip_vm_shutdown is false. beginning vm shutdown procedure.
2019-11-21 21:01 action: Mint is running. shutting down.
Domain Mint is being shutdown

2019-11-21 21:01 information: performing 20 30 second cycles waiting for Mint to shutdown cleanly
2019-11-21 21:01 information: cycle 1 of 20: waiting 30 seconds before checking if the vm has shutdown
2019-11-21 21:02 information: Mint is shut off. can_backup_vm set to y
2019-11-21 21:02 action: actually_copy_files is 1.
2019-11-21 21:02 action: can_backup_vm flag is y. starting backup of Mint configuration, nvram, and vdisk(s).
sending incremental file list
Mint.xml

sent 6,483 bytes received 35 bytes 13,036.00 bytes/sec
total size is 6,389 speedup is 0.98
2019-11-21 21:02 information: backup of Mint xml configuration to /mnt/user/Backup/vm_sicherung/Mint/20191121_2101_Mint.xml complete.
Mint.xml:5: namespace warning : xmlns: URI unraid is not absolute

^
sending incremental file list
065a6081-e954-0913-370d-b6001262fb61_VARS-pure-efi.fd

sent 131,240 bytes received 35 bytes 262,550.00 bytes/sec
total size is 131,072 speedup is 1.00
2019-11-21 21:02 information: backup of Mint nvram to /mnt/user/Backup/vm_sicherung/Mint/20191121_2101_065a6081-e954-0913-370d-b6001262fb61_VARS-pure-efi.fd complete.
Mint.xml:5: namespace warning : xmlns: URI unraid is not absolute

^
Mint.xml:5: namespace warning : xmlns: URI unraid is not absolute

^
Mint.xml:5: namespace warning : xmlns: URI unraid is not absolute

^
Mint.xml:5: namespace warning : xmlns: URI unraid is not absolute

^
'/mnt/user/VMs/Mint/vdisk1.img' -> '/mnt/user/Backup/vm_sicherung/Mint/20191121_2101_vdisk1.img'
2019-11-21 21:05 information: backup of vdisk1.img vdisk to /mnt/user/Backup/vm_sicherung/Mint/20191121_2101_vdisk1.img complete.
2019-11-21 21:05 information: the extensions of the vdisks that were backed up are img.
2019-11-21 21:05 action: vm_original_state is running. starting Mint.
Domain Mint started

2019-11-21 21:05 information: started creating new tarball.
2019-11-21 21:05 information: creating blank backup file list at /mnt/user/Backup/vm_sicherung/Mint/backup_file_list.txt.
20191121_2101_vdisk1.img
20191121_2101_Mint.xml
20191121_2101_065a6081-e954-0913-370d-b6001262fb61_VARS-pure-efi.fd
2019-11-21 21:24 information: removing backup file list at /mnt/user/Backup/vm_sicherung/Mint/backup_file_list.txt.
2019-11-21 21:24 information: finished creating new tarball.
2019-11-21 21:24 information: removed xml, nvram, and image files that were compressed.
2019-11-21 21:24 information: backup of Mint to /mnt/user/Backup/vm_sicherung/Mint completed.
2019-11-21 21:24 information: cleaning out backups older than 30 days in location ONLY if newer files exist in /mnt/user/Backup/vm_sicherung/Mint/
2019-11-21 21:24 information: cleaning out backups over 5 in location /mnt/user/Backup/vm_sicherung/Mint/
find: '/mnt/user/Backup/vm_sicherung/Mint/*.xml': No such file or directory
2019-11-21 21:24 information: did not find any config files to remove.
find: '/mnt/user/Backup/vm_sicherung/Mint/*.fd': No such file or directory
2019-11-21 21:24 information: did not find any nvram files to remove.
/tmp/user.scripts/tmpScripts/vm_sicherung/script: line 3301: [: : integer expression expected
/tmp/user.scripts/tmpScripts/vm_sicherung/script: line 3301: [: : integer expression expected
/tmp/user.scripts/tmpScripts/vm_sicherung/script: line 3301: [: : integer expression expected
/tmp/user.scripts/tmpScripts/vm_sicherung/script: line 3301: [: : integer expression expected
2019-11-21 21:24 information: did not find any image files to remove.
2019-11-21 21:24 information: did not find any compressed files to remove.
2019-11-21 21:24 information: finished attempt to backup
Mint
to /mnt/user/Backup/vm_sicherung.
2019-11-21 21:24 information: cleaning out logs over 12.
2019-11-21 21:24 information: removed '/mnt/user/Backup/vm_sicherung/logs/20191027_0630_unraid-vmbackup.log'
2019-11-21 21:24 information: cleaning out error logs over 12.
2019-11-21 21:24 information: did not find any error log files to remove.
2019-11-21 21:24 Stop logging to log file.

 

Share this post


Link to post
56 minutes ago, bastl said:

Mint.xml:5: namespace warning : xmlns: URI unraid is not absolute

The line 5 in the xml looks like the following in my VM:


    <vmtemplate xmlns="unraid" name="Debian" icon="linux-mint.png" os="debian"/>

Another "maybe" warning is at the end of the logs:


/tmp/user.scripts/tmpScripts/vm_sicherung/script: line 3301: [: : integer expression expected

In case I should test something or you need some more info, let me know!

 

 

Yeah, both of those are not easily avoided currently. However, neither of them should cause an issue.

 

The "namespace warning" is because xmlns is just "unraid", and the parser is expecting an absolute path (like http://unraid.net/foo). Unless the way UnRAID does xml creation is changed to use an absolute URI, that error will continue to appear.

 

The "integer expression expected" is because of a regular expression I'm using in the script. In the next update I'm intending to catch the error and handle it more gracefully. Essentially though it's just letting you know that of the two variables it is comparing, at least one of them is not actually a number.

 

Share this post


Link to post

@JTok Thanks for the explanation. If you have some test builds and need someone to test, feel free to ask me 😉

Share this post


Link to post

It hasn't been very long since the last update, but I had some other changes I wanted to get added before the weekend.

I've tested this version as thoroughly as I am able, but it has a lot of under-the-hood changes this time, so I apologize now if I missed something.

 

release highlights (full notes below):

1) the ability to back up *all* VMs without explicitly listing them.

2) option to choose your own snapshot extension.

3) the option to fall back to a standard backup if a snapshot fails (this means shutting down the VM like normal).

4) the option to pause the VMs instead of shutting them down during a standard backup. (fair warning, I do not know how safe this actually is, so use at your own risk.)

 

 

v1.2.0 - 2019/11/27

Starring Tom Hanks

 

- major rewrites to make script smaller, slightly more efficient, and more modular.

- added option to choose different snapshot extension.

- added option to allow all vms to be backed up without having to explicitly list them.

- added option to revert back to standard backup if snapshot fails.

- added option to pause vms during standard backups instead of shutting down.

- added support for pulling nvram extension from the config file.

- fixed 'integer expression expected' error when performing regular expression integer comparisons.

- fixed dry run option not working.

- workaround for 'namespace warning' error when working with config file.

- improved readability of log file by removing unnecessary line breaks.

 

Script here:

https://github.com/JTok/unraid-vmbackup/tree/v1.2.0

 

-JTok

Share this post


Link to post

I haven't actually used this yet, i just happened across a SpaceInvader video about it as i'm looking at all my various backup solutions at the moment. It looks pretty neat! It would be even awesomer as an 'App', but that's just being greedy :)

 

A suggestion that immediately pops into mind now you've added "all VMs" without having to list them, is the reverse: an "exclude VMs" list - in other words all the VMs except these.

 

Just an idea from someone who wandered by :)

Share this post


Link to post
10 hours ago, Derek_ said:

It would be even awesomer as an 'App', but that's just being greedy :)

Funny you should mention that 😁. I'm getting very close to having a beta version of the script as a plugin available. I'm expecting to have that done in the next few days (maybe even as early as tomorrow).

 

10 hours ago, Derek_ said:

A suggestion that immediately pops into mind now you've added "all VMs" without having to list them, is the reverse: an "exclude VMs" list - in other words all the VMs except these.

A good idea. I think I have a relatively elegant way to implement that in mind. Expect it to show up in a future version. 👍

Share this post


Link to post
56 minutes ago, JTok said:

Funny you should mention that 😁. I'm getting very close to having a beta version of the script as a plugin available. I'm expecting to have that done in the next few days (maybe even as early as tomorrow).

 

A good idea. I think I have a relatively elegant way to implement that in mind. Expect it to show up in a future version. 👍

YES!! Would be sweet to see a plugin with a GUI or sorts for this

Share this post


Link to post

I had hoped my next post would be about the plugin beta, but I'm still working on that. Though it should be ready for testing very soon.

 

This is just a bug-fix for the regular script (details below).

 

There is some bad news about the bug. If you were running v1.2.0 with snapshots and experienced the bug explained below, you will need to fix your VMs before the backup script will work with them again. The good news is that running the backup script will not cause any further issues, but backups will fail for affected VMs.

 

There are two ways to fix it.

The first is to manually fix it yourself, which is safest if you understand what you are doing. I would highly recommend doing that if you are comfortable.

The only two commands you have to run against *each* vdisk that has a broken snapshot are:

virsh blockcommit "$vm" "${vdisk_specs[$disk]}" --active --wait --verbose --pivot

rm -fv "$disk_directory/$snap_name"

where "$vm" is the name of the vm and "${vdisk_specs[$disk]}" is the value for dev for each vdisk in your VM's xml. Keep the double quotes.

The xml line will look like:

<target dev='hdc' bus='scsi'/>

the second command above is VERY dangerous, so be certain you know what you are doing. You will change the quoted part to the path of the SNAPSHOT vdisk, keeping the quotes this time as well. Be very careful not to accidentally use the path of your actual vdisk. It will then delete the no longer needed snapshot.

 

A second option is to use the attached "fix-stuck-snapshots" script. The script will only work on VMs that are running, so be sure that any VM that needs fixed is turned on.

I have tested it on my system, and I tried to make it as safe as possible... but I cannot, and will not, guarantee that something couldn't make it delete the wrong vdisk and cause you to lose data. Use at your own risk.

 

As long as you are using the default snapshot extension from the previous script, you should be able to just run it once and then remove it. It will push some event notifications and log to the syslog.

 

If you have any questions or need any help feel free to reply here, and I'll do my best.

 

 

v1.2.1 - 2019/12/11

Moth-man is Real

 

- fixed bug that could cause snapshots not to be removed in specific situations.

 

 

Script here:

https://github.com/JTok/unraid-vmbackup/tree/v1.2.1

 

-JTok

 

 

Extra details for those that care:

The script would not remove a snapshot if a VM that was shut off got backed up before one that was running.

If no VMs were off, then this would not happen. If the VMs that were off got backed up after all the ones that were on, this would not happen.

fix-stuck-snapshots.sh

Edited by JTok
clarity

Share this post


Link to post
On 12/9/2019 at 3:44 AM, JTok said:

Funny you should mention that 😁. I'm getting very close to having a beta version of the script as a plugin available. I'm expecting to have that done in the next few days (maybe even as early as tomorrow).

 

A good idea. I think I have a relatively elegant way to implement that in mind. Expect it to show up in a future version. 👍

Sweet!

 

I don't even use it yet, but i'd like to buy you a coffee (or beer.. or whatever). Where to donate?

Share this post


Link to post

The biggest change in this release is that when backup_all_vms is enabled, vms_to_backup becomes an exclusion list.

 

v1.2.2 - 2019/12/18

Sam Vimes

 

- added logging to local vm config dump actions.

- added ability to use vms_to_backup as an exclusion list when backup_all_vms is enabled.

- fixed rm commands missing -fv options.

 

Script here:

https://github.com/JTok/unraid-vmbackup/tree/v1.2.2

 

-JTok

Share this post


Link to post

It is official! I finally have the first beta version of the plugin available here:

 

-JTok

Share this post


Link to post

Big fat thanks to @sjerisman for doing all the work to get a zstandard compression option added to the script!

 

This is going to be significantly faster than using the existing compression option, as well as much more efficient. However, it is not backwards compatible, so if you switch you will want to manually trim any old compressed backups.

 

For those of you that are currently using the plugin, this is coming, but it will be a bit longer. With the plugin being so new, there are some additional kinks to work out as well.

 

v1.3.0 - 2020/01/15
Better than standard

- added option to use zstd inline compression.

 

Script here:

https://github.com/JTok/unraid-vmbackup/tree/v1.3.0

 

-JTok

Share this post


Link to post
13 hours ago, JTok said:

Big fat thanks to @sjerisman for doing all the work to get a zstandard compression option added to the script!

@JTok - Thanks for the shout out, and thanks for reviewing and releasing my changes so quickly!  I did this as much for my own benefit as anything else.  ;)

 

13 hours ago, JTok said:

This is going to be significantly faster than using the existing compression option, as well as much more efficient.

Just to give everyone a bit of an idea of how much faster and more efficient this new inline compression option is, here are some results from one of my UnRaid servers:

 

I currently have 4 (fairly small) VMs on this server (Win10, Win7, Arch Linux, and AsteriskNOW) running on a NVMe unassigned device and backing up directly to a dual parity HDD array (bypassing the SSD cache) with TurboWrite enabled.  This is running on a 4th Gen quad core CPU (i7-4770) with 32GB of DDR3 RAM.

* The 4 VMs have a total of 60 G of raw image files with a sparse allocation of 33 G

* The old post compression option took 55 minutes and produced a total of 17.15 G of compressed .tar.gz files

* The new inline zstd compression option took less than 3 minutes and produced a total of 16.83 G of compressed .zst image files (using the default compression level of 3 and 2 compression threads)

* Some of these VMs (Win10 and ArchLinux) have compressed file systems inside the vdisk images as well.  Without this, the vdisk sparse allocation would have been larger and the old compression code would have been even slower.

 

OS           Size  Alloc  .tar.gz  .zst
-----------  ----  -----  -------  ----
Win10        30G   9.1G   6.7G     6.7G
Win7         20G   18G    8.4G     8.2G
ArchLinux    5.0G  2.0G   1.4G     1.4G
AsteriskNOW  5.0G  3.9G   645M     573M

 

I feel MUCH better now about having daily scheduled backups that go directly to the HDD array and allowing the disks to spin back down again so much more quickly!

 

 

 

Share this post


Link to post

Another big thanks to @sjerisman for adding this feature.

 

Again, for anyone using the plugin, the features that get added here will make their way into the plugin before too long.

 

v1.3.1 - 2020/01/21

So Say We All

 

- added option to create a vm specific log in each vm's sub-folder.

 

Script here:

https://github.com/JTok/unraid-vmbackup/tree/v1.3.1

 

-JTok

  • Like 1
  • Thanks 1

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.