Hi,
I sometimes have an issue with backups. Some virtual machines are still locked after the backup job run. Maybe this is linked to an automatic restart job, which restarts virtual machines when they get stuck. So not to end up with unmanageable locked vms I scheduled an unlock script, which clears all backup locks on a pve node, if no vzdump job is running.
This is the script:
I sometimes have an issue with backups. Some virtual machines are still locked after the backup job run. Maybe this is linked to an automatic restart job, which restarts virtual machines when they get stuck. So not to end up with unmanageable locked vms I scheduled an unlock script, which clears all backup locks on a pve node, if no vzdump job is running.
This is the script:
Code:
#!/bin/bash
declare -rx PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
declare -rx LC_ALL=C
get_vms_with_backup_lock() {
this_host="$(hostname)"
pvesh get /cluster/resources --output-format=json \
| jq -r '.[] | select(.type=="qemu") | select (.node=="'"$this_host"'") | select (.lock=="backup") | .vmid'
}
mylog() {
echo "$(date): $*"
}
main() {
which jq &>/dev/null || { echo "required program jq is missing. please install. aborting";exit 1;}
for((x=1;x<=60;x++));do
if ps ax | grep -q "task UPID.*vzdump" ; then
mylog "dump is still running. waiting"
else
for vmid in $(get_vms_with_backup_lock);do
qm unlock $vmid
done
mylog "vm unlock process finished"
exit 0
fi
sleep 60
done
mylog "giving up waiting. aborting vm unlock process."
}
main 2>&1 &
Last edited: