JTok / unraid.vmbackup

a plugin for backing up VMs in unRAID including vdisks and configuration files.
51 stars 4 forks source link

Backup fails due to ISO mount specifed in the VM settings, reporting ["$vdisk_path"]: bad array subscript` #26

Open burntoc opened 3 years ago

burntoc commented 3 years ago

My backup attempts with the latest versions fails, as this single error seems to be bypassing the actual backup:

2021-03-10 10:12:49 information: /mnt/user/_backups_unraid1/VMs/GamingPC exists. continuing. /tmp/vmbackup/scripts/default/user-script.sh: line 424: vdisk_types["$vdisk_path"]: bad array subscript

I found others with this issue, and it lead me to believe it was failing on an ISO I still had mounted and/or the SSD I pass through directly by-id. I wanted to keep the latter if possible, so I removed the VirtIO Drivers ISO and ran it again and the backup appears to have completed just fine. Haven't tried a restore, but it looks really promising.

If I remove VirtIO Drivers ISO from my VM then it starts crashing within a minute - two at the most. Over and over. If I put that back, it works fine. I know it shouldn't do that, but it does, and it doesn't matter whether I store the ISO on the array or on a UA drive, the VM Backup script gives this error and fails if that ISO is in the settings:

/tmp/vmbackup/scripts/default/user-script.sh: line 424: vdisk_types["$vdisk_path"]: bad array subscript

Any way we fix this issue, for this very common situation?

BoKKeR commented 2 years ago

I am facing the same problem. removing the iso helped, but my use case dont require it mounted

realizelol commented 2 years ago

Hi there,

this should be a temporary fix:

curl -sL https://raw.githubusercontent.com/realizelol/unraid.vmbackup/master/source/scripts/default-script.sh \
  > /usr/local/emhttp/plugins/vmbackup/scripts/default-script.sh

after this you can change a value in Settings -> VM Backup -> Settings and change it back to the wanted value and click "apply" then the user-script.sh will be generated with the new pre-script.sh. Or just do it by command line: /usr/local/emhttp/plugins/vmbackup/scripts/commands.sh update_user_script default rebuild_text_files

or just add this to your Pre-Script in Settings -> VM Backup -> Upload Scripts so it will be overridden before every backup (haven't tested this):

#!/bin/bash
#arrayStarted=true
#noParity=true
PATH=".:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin"
export PATH=${PATH}

# download the fixed version by realizelol
curl -sL https://raw.githubusercontent.com/realizelol/unraid.vmbackup/master/source/scripts/default-script.sh \
  > /usr/local/emhttp/plugins/vmbackup/scripts/default-script.sh

# update config "default" so user-script will be updated by new values of downloaded "default-script.sh"
/usr/local/emhttp/plugins/vmbackup/scripts/commands.sh update_user_script default rebuild_text_files

# or if you use other config files rename "someotherconfigname" by your config name and remove "#"
# /usr/local/emhttp/plugins/vmbackup/scripts/commands.sh update_user_script someotherconfigname rebuild_text_files 


If the disk has no source it will be faked to /tmp/dummy.nobkdummy, the extension nobkdummy is already excluded in code. As an example:

2022-01-23 17:43:05 information: backup of /mnt/user/domains/elementaryOS/vdisk1.img vdisk to /mnt/user/ur-backup/vms/domains/elementaryOS/20220123_1738_vdisk1.img complete.
2022-01-23 17:43:05 information: extension for /tmp/dummy.nobkdummy on elementaryOS was found in vdisks_extensions_to_skip. skipping disk.
2022-01-23 17:43:05 information: extension for /mnt/disk2/iso/elementaryos-6.1-stable.20211218-rc.iso on elementaryOS was found in vdisks_extensions_to_skip. skipping disk.
2022-01-23 17:43:05 information: the extensions of the vdisks that were backed up are img.

Note:

This will maybe only fix the default backup method not the snapshot method! Let me know someone need that too.


@JTok feel free to update your script or let me know if you want a PR. Hope you're doing fine.. haven't heard anything from you for a while...


Best regards realizelol

realizelol commented 2 years ago

Pre-Script has been tested. As after a reboot the script is overridden. Here's the correct pre-script:

#!/bin/bash
#arrayStarted=true
#noParity=true
PATH=".:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin"
export PATH=${PATH}
#### --- END OF SCRIPT DEFAULT --- ####

#### ---   Fix by realizelol START   --- ####

# get script config name
SCRIPTPATH="$(realpath ${0} | sed 's/\/'$(basename ${0})'//g')"
SCRIPT_CONFIG_NAME="${SCRIPTPATH##/*/}"
# or set it manually:
#SCRIPT_CONFIG_NAME="default"

# reset UPDATED to 0
UPDATED=0
# download the fixed version by realizelol into /tmp folder
# 5 seconds connect timeout, maximum download time 10 seconds, maxmimum 5 retries
# 0 delay between retries, maximum of 60 seconds until script is downloaded
curl --connect-timeout 5 \
  --max-time 10 \
  --retry 5 \
  --retry-delay 0 \
  --retry-max-time 60 \
  "https://raw.githubusercontent.com/realizelol/unraid.vmbackup/master/source/scripts/default-script.sh" \
  > /tmp/default-script.sh

# check if local and downloaded version has been changed
if ! cmp /usr/local/emhttp/plugins/vmbackup/scripts/default-script.sh /tmp/default-script.sh >/dev/null; then
  # move script into place
  cp -f /tmp/default-script.sh /usr/local/emhttp/plugins/vmbackup/scripts/default-script.sh
  # set variable UPDATED to 1 (script has been updated)
  UPDATED=1
fi

# if UPDATED=1 restart script with updated user script files
if [[ ${UPDATED} -eq 1 ]]; then
  # update config "default" so user-script will be updated by new values of downloaded "default-script.sh"
  /usr/local/emhttp/plugins/vmbackup/scripts/commands.sh update_user_script ${SCRIPT_CONFIG_NAME} rebuild_text_files
  # move the updated user-script to temporary folder where it will be executed from
  cp /boot/config/plugins/vmbackup/user-script.sh /tmp/vmbackup/scripts/${SCRIPT_CONFIG_NAME}/user-script.sh
  # make temporary user-script.sh executable.
  chmod +x /tmp/vmbackup/scripts/${SCRIPT_CONFIG_NAME}/user-script.sh
  # sleep 2 seconds before execution
  sleep 2
fi

#### ---    Fix by realizelol END    --- ####

Edit: Add line chmod +x /tmp/vmbackup/scripts/${SCRIPT_CONFIG_NAME}/user-script.sh to fix first execution: FROM:

  cp /boot/config/plugins/vmbackup/user-script.sh /tmp/vmbackup/scripts/${SCRIPT_CONFIG_NAME}/user-script.sh
  # sleep 2 seconds before execution

TO:

  cp /boot/config/plugins/vmbackup/user-script.sh /tmp/vmbackup/scripts/${SCRIPT_CONFIG_NAME}/user-script.sh
  # make temporary user-script.sh executable.
  chmod +x /tmp/vmbackup/scripts/${SCRIPT_CONFIG_NAME}/user-script.sh
  # sleep 2 seconds before execution
realizelol commented 5 months ago

This should be fixed by PR https://github.com/JTok/unraid.vmbackup/pull/39

So please remove/revert my previously mentioned pre-script/changes.

# set your config name if it differs 'default'
SCRIPT_CONFIG_NAME="default"

# restore default pre-script:
cp /boot/config/plugins/vmbackup/pre-script.sh /boot/config/plugins/vmbackup/pre-script.sh.bk
sed -i '/#### ---   Fix by realizelol START   --- ####/,/#### ---    Fix by realizelol END    --- ####/d' /boot/config/plugins/vmbackup/pre-script.sh
sed -i '/#### --- END OF SCRIPT DEFAULT --- ####/d' /boot/config/plugins/vmbackup/pre-script.sh

# if my modified version is found restore the new version of JTok
if grep -q "^#version=v0.2.5.1" /usr/local/emhttp/plugins/vmbackup/scripts/default-script.sh; then
  curl --connect-timeout 5 \
    --max-time 10 \
    --retry 5 \
    --retry-delay 0 \
    --retry-max-time 60 \
    "https://raw.githubusercontent.com/JTok/unraid.vmbackup/master/source/scripts/default-script.sh" \
    > /usr/local/emhttp/plugins/vmbackup/scripts/default-script.sh

  # use the updated version by JTok
  /usr/local/emhttp/plugins/vmbackup/scripts/commands.sh update_user_script ${SCRIPT_CONFIG_NAME} rebuild_text_files
  cp /boot/config/plugins/vmbackup/user-script.sh /tmp/vmbackup/scripts/${SCRIPT_CONFIG_NAME}/user-script.sh
  chmod +x /tmp/vmbackup/scripts/${SCRIPT_CONFIG_NAME}/user-script.sh
fi