Get job information in vzdump-hook

StephenW

New Member
Mar 21, 2024
6
1
3
Hi

Still working on a Proxmox setup, hope to convince our customers to switch.

I have edited my vzdump-hook-script to send an email when backup is OK and when it failed.

I can get the VM ID in the script, but cannot see how to get any Job information like Job ID, Job name, etc
I would like to use the $phase job-start, job-end, job-abort.
Trying not to have to bombard customers with an email for every VM when all their VM's are in one job.

My edit
Code:
    # send email to customer
    if ($phase eq 'backup-end') {
        $to = '*****';
        $from = '*****';
        $subject = "VM${vmid} Backup Success";
        $message = 'Success';

        open(MAIL, "|/usr/sbin/sendmail -t");

        # Email Header
        print MAIL "To: $to\n";
        print MAIL "From: $from\n";
        print MAIL "Subject: $subject\n\n";
        # Email Body
        print MAIL $message;

        close(MAIL);
        #print "Email Sent Successfully\n";

    }

    # send email to customer
    if ($phase eq 'backup-abort') {

        $to = '****';
        $from = '****';
        $subject = "VM${vmid} Backup Failed";
        $message = 'Failed';

        open(MAIL, "|/usr/sbin/sendmail -t");

        # Email Header
        print MAIL "To: $to\n";
        print MAIL "From: $from\n";
        print MAIL "Subject: $subject\n\n";
        # Email Body
        print MAIL $message;

        close(MAIL);
        #print "Email Sent Successfully\n";

    }
 
Hi!
this is currently not possible AFAIK, *but* you can set specific script for every backup job.
This option is not yet available in the UI, so we need to use the API like this:

1) Get the backup-id of the job from /etc/pve/jobs.cfg
2) Execute pvesh set /cluster/backup/backup-<id> --script /your-script.pl

More info about the jobs.cfg file here (this includes the script parameter): https://pve.proxmox.com/pve-docs/pve-admin-guide.html#vzdump_jobs