[Script] clear backup locks after vzdump jobs

hellfire

Renowned Member
Aug 17, 2016
79
44
83
46
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:

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:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!