Backup Hook Script

RNab

Member
Jun 20, 2021
31
3
13
34
Hi,

I have been looking around but honestly struggled to find documentation on that.

I’m trying to setup a hook script to run at the end of my PBS and regular Backup Job.

What I’m trying to do is one each VM backup is finished, depending on the status, I would do a given action for that VM. Similarly when the whole backup job has finished.

Could anyone point me towards where I can find info on :
- The meaning of each $phase
- how to retrieve a status code (success, fail, abort etc) for each vm backup as well as the entire job ?

Thanks
 
There is no documentation beside the comments in the example script: https://git.proxmox.com/?p=pve-mana...e70a4a9775438ab658da2191;hb=refs/heads/master

First argument is the phase. For an action at the end of the backup job you want to check against "job-end" and maybe "job-abort" because, if I remember right, an aborted backup job will skip the "job-end" phase.

For each VM backup you want to check for the "backup-end" and maybe "backup-abort" phase.

Not sure if there is a status code from within the script. You are probably limited to an successful "end" and an failed "abort".
Maybe you could parse the log of the backup to get your status while being in the "log-end" phase of a backup by reading the "LOGFILE" environment variable.

Also keep in mind that the hook script will be called for each single phase. So for more complex scripts you might need to write some data in files so a later call of the hook script at another phase can continue what another phase started.
 
Last edited:
oh so you mean a failure is a job abort actually ? Ok that makes it a lot clearer indeed.

Ok thanks a lot for your help. I will do some tests in my side.
 
Hello,

this is the first hit on goolge for me, so I'm posting my issue:
Code:
118: 2024-02-19 04:26:10 INFO: _____-----_____
118: 2024-02-19 04:26:10 INFO: Use of uninitialized value in concatenation (.) or string at /usr/sbin/sanoid line 39.
118: 2024-02-19 04:26:10 INFO: FATAL: cannot load /root/ct118/sanoid.defaults.conf - please restore a clean copy, this is not a user-editable file! at /usr/sbin/sanoid line 870.
118: 2024-02-19 04:26:10 INFO: Use of uninitialized value in concatenation (.) or string at /usr/sbin/sanoid line 39.
118: 2024-02-19 04:26:10 INFO: FATAL: cannot load /root/ct118/sanoid.defaults.conf - please restore a clean copy, this is not a user-editable file! at /usr/sbin/sanoid line 870.

relevant part from hook.pl:
Code:
if ($phase eq 'backup-end') {
        #zu der zeit ist der container noch aus wenn mode=stop
        print "_____-----_____\n";
        system ("/usr/sbin/sanoid --take-snapshots --verbose --configdir=/root/ct118");
        system ("/usr/sbin/sanoid --prune-snapshots --verbose --configdir=/root/ct118");

and during writing and checking this script
I found my issue. After system(...) I'm missing == 0 || die "enabling storage $storeid failed";
Just in case anybody else made the same mistake.
 

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!