vzdump Backup Hook Script is ignored

RockNLol

Member
Sep 13, 2020
45
2
13
hi,
I'm trying to wake my HTPC which hosts a PBS-VM up before starting a backup. So I wrote a little bash script as hook for vzdump:

Bash:
root@pve:~# cat /usr/bin/backup-hook-script
#!/bin/bash

touch /var/tmp/hooktest # for testing purposes

# INSTALL net rpc COMMAND BY RUNNING:
# apt update && apt install samba-common-bin

# VARIABLES:
WOLUUID='uuid=<opnsense uuid>'
APIKEY="<opnsense apikey>"
SECRET="<opnsense apikey secret>"
HOST="opnsense.mydomain.local"

case "${1}" in

    job-start)
        # wake HTPC that hosts PBS-VM

        # wake via wakeonlan command
        #wakeonlan <macaddress>

        # wake via opnsense API
        curl -XPOST -d $WOLUUID -g -k -u $APIKEY:$SECRET "https://"$HOST":443/api/wol/wol/set/"

        echo "waiting 90s..."
        sleep 90
        echo "PBS should be up now. Continuing..."
    ;;


    job-end)
        net rpc -S <HTPC-IP> -U <user>%<supersecretpassword> shutdown -t 1 # shut HTPC down again
    ;;
esac

... and modified /etc/vzdump.conf:
Code:
root@pve:~# cat /etc/vzdump.conf
# vzdump default settings

#tmpdir: DIR
#dumpdir: DIR
#storage: STORAGE_ID
#mode: snapshot|suspend|stop
#bwlimit: KBPS
#ionice: PRI
#lockwait: MINUTES
#stopwait: MINUTES
#size: MB
#stdexcludes: BOOLEAN
#mailto: ADDRESSLIST
#maxfiles: N
script: /usr/bin/backup-hook-script
#exclude-path: PATHLIST
#pigz: N

if i run /usr/bin/backup-hook-script job-start or /usr/bin/backup-hook-script job-end the HTPC/PBS wakes up and shuts down correctly, so my script should be working. To see if the script even gets executed I added the line touch /var/tmp/hooktest # for testing purposes, but theres no /var/tmp/hooktest file created when I run the backup. I get TASK ERROR: could not activate storage 'PBS': PBS: error fetching datastores - 500 Can't connect to pbs.mydomain.local:8007 (No route to host) straight away.

What did I do wrong?
 
Last edited:
activating the storage happens before the hook script is called..
 
  • Like
Reactions: RockNLol
Well, thats a fundamental issue in my plan then. I guess I have to wake it up by schedule then, or does anybody have a better idea?
 
if you just want this for scheduled backups, you can also adapt the generated cron entry to call your script before/after the vzdump call, but you lose the ability to edit that job via the API/GUI then..
 
  • Like
Reactions: RockNLol
Thats a good idea. Not being able to edit it via GUI/API is not a problem, scheduled backup should be a "setup once and leave it" kind of deal anyways.

*another idea: wake the PBS up by schedule and trigger the backup on the PVE remotely from a script on the PBS. I'll have a look into the API in the evening.
 
Last edited:
activating the storage happens before the hook script is called..
To me there should be another hook calling out a script before storage activation is invoked.

Pretty frustrating that the flow with Wake-on-lan is not possible off the shelf
 
there is nowadays (well, in the next pve-manager version bump ;)) - the phase is called `job-init`, and the storage config is reloaded after it has been called to pick up any potential changes by the hookscript. so you can enable a storage, do WOL, wait for it to come up, and only then return from the hook script for the backup to proceed.
 
  • Like
Reactions: Jarek Hartman
Thank you, Fabian. I have a parallel requirement that this should meet.
At the moment I have a bunch of "utility" scripts, which I run inside a docker container (for historic reasons) inside a VM on pve.
A crontab runs a python script that does a bunch of sshs into the pve host to do a wake-on-lan, mount the storage, un-disable it, run the backup, disable the storage and unmount it.

The disabling and unmounting is necessary to avoid a mountpoint persisting on the host for a machine that is asleep, which can result in bad things happening.

One thing that I had to solve was to generate the list of vms/cts to be backed-up. I was looking for a way to interrogate a disabled backup job, but didn't find it. The "hack" solution I found was to create a "Backup_Role" and backup group, and assign permission to "Backup_Role" in vm/ct. This can be read via pvesh get /access/acl on the host.

It will be much cleaner if the hook scripts can remove my need for this workaround and hack.
 
the job itself is not modifiable by the hookscript (at least not in a way that would be picked up by the current execution). if you need this kind of flexibility, not using the built-in scheduler and instead writing your own wrapper around vzdump (the CLI, or the API endpoint) and scheduling that via a systemd timer or cron job seems like a good solution.
 

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!