public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-manager 1/1] feat: pass backup status to hook script on job-end/job-abort
       [not found] <20250923174007.84121-1-proxmox8914@herold.me>
@ 2025-09-23 17:40 ` Constantin Herold via pve-devel
  2025-09-24  9:40 ` [pve-devel] [PATCH pve-manager 0/1] " Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Constantin Herold via pve-devel @ 2025-09-23 17:40 UTC (permalink / raw)
  To: pve-devel; +Cc: Constantin Herold

[-- Attachment #1: Type: message/rfc822, Size: 4734 bytes --]

From: Constantin Herold <proxmox8914@herold.me>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-manager 1/1] feat: pass backup status to hook script on job-end/job-abort
Date: Tue, 23 Sep 2025 19:40:07 +0200
Message-ID: <20250923174007.84121-2-proxmox8914@herold.me>

Signed-off-by: Constantin Herold <proxmox8914@herold.me>
---
 PVE/VZDump.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index defe9e0a..eab19d91 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -830,8 +830,8 @@ sub run_hook_script {
     $ENV{STOREID} = $opts->{storage} if $opts->{storage};
     $ENV{DUMPDIR} = $opts->{dumpdir} if $opts->{dumpdir};
 
-    foreach my $ek (qw(vmtype hostname target logfile)) {
-        $ENV{ uc($ek) } = $task->{$ek} if $task->{$ek};
+    foreach my $ek (qw(vmtype hostname target logfile errcount)) {
+        $ENV{ uc($ek) } = $task->{$ek} if defined $task->{$ek};
     }
 
     run_command($logfd, $cmd);
@@ -1445,7 +1445,7 @@ sub exec_backup {
         }
 
         $self->{'backup-provider'}->job_cleanup() if $self->{'backup-provider'};
-        $self->run_hook_script('job-end', undef, $job_end_fd);
+        $self->run_hook_script('job-end', { errcount => $errcount }, $job_end_fd);
     };
     my $err = $@;
 
@@ -1455,7 +1455,7 @@ sub exec_backup {
             $err .= "job cleanup for external provider failed - $@" if $@;
         }
 
-        eval { $self->run_hook_script('job-abort', undef, $job_end_fd); };
+        eval { $self->run_hook_script('job-abort', { errcount => $errcount }, $job_end_fd); };
         $err .= $@ if $@;
         debugmsg('err', "Backup job failed - $err", undef, 1);
     } else {
-- 
2.51.0



[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pve-devel] [PATCH pve-manager 0/1] feat: pass backup status to hook script on job-end/job-abort
       [not found] <20250923174007.84121-1-proxmox8914@herold.me>
  2025-09-23 17:40 ` [pve-devel] [PATCH pve-manager 1/1] feat: pass backup status to hook script on job-end/job-abort Constantin Herold via pve-devel
@ 2025-09-24  9:40 ` Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2025-09-24  9:40 UTC (permalink / raw)
  To: Constantin Herold, pve-devel; +Cc: Lukas Wagner

Am 23.09.25 um 19:40 schrieb Constantin Herold:
> I've been using the pve manager vzdump hook to do custom things after a backup is done e.g. backup some more files, call a webhook for monitoring, etc.
> 
> However there is currently a big drawback, the job state does not get passed, so there is no way to tell whether the backup was succesfull or not.
> 
> I recently had some drive issues which resulted in 1 vm backup failing, if i had not checked the mailnotification i would have never catched that.
> 
> 
> e.g. /etc/vzdump.conf with `script: /root/backuphook.sh`
> 
> cat << 'EOF' > /root/backuphook
> #!/bin/bash
> 
> cd /tmp
> DATE=$(date +"%d.%m.%Y")
> FILENAME="backup_$DATE.env"
> echo "" >> "$FILENAME"
> chmod 700 "$FILENAME"
> echo "Arguments: $@" >> "$FILENAME"
> printenv >> "$FILENAME"
> echo -e "\n\n" >> "$FILENAME"
> EOF
> 
> 
> all the backuphook gets passed is the following:
> ```
> Arguments: job-end  
> PWD=/tmp
> LVM_SUPPRESS_FD_WARNINGS=1
> SHLVL=1
> STOREID=backup
> LC_ALL=C
> OLDPWD=/
> _=/usr/bin/printenv
> ```
> 
> No way to tell whether the backup was succesfull, can't even grep the backup log for it etc.
> 
> I've been using this simple patch to pass the errcount to the `job-end` and `job-abort` stage
> 
> This way you can check now if it was succesfull or not, e.g:
> 
> cat << 'EOF' > /root/backuphook
> #!/bin/bash
> 
> if [[ "$*" != *job-end* ]]; then
>     exit 0
> fi
> 
> if [ "$ERRCOUNT" -gt 0 ]; then
>     # alert on broken backup (could be drive issues etc.)
>     # call webhook / trigger monitoring alert

FWIW, for this the notification system might be better suited, it already
has support for various targets, including web hooks. That doesn't mean
adding info to the hook is not needed, just wanted to mention that it exist
and that one option might be to provide support for trigger a dedicated
notification for each single backup "sub-job", which would avoid the need
for having a custom hook if it's just to get a dedicated notification / hook
ASAP for each failed backup of a guest (vs. the overall result of the backups
of all guests).


> else
>     # do some more things after succesfull backup
> fi
> EOF
> 
> 
> Would be great if this could be merged.
> 
> Best regards
> Constantin
> 
> 
> Constantin Herold (1):
>   feat: pass backup status to hook script on job-end/job-abort
> 
>  PVE/VZDump.pm | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pve-devel] [PATCH pve-manager 0/1] feat: pass backup status to hook script on job-end/job-abort
@ 2025-09-23 17:40 Constantin Herold via pve-devel
  0 siblings, 0 replies; 3+ messages in thread
From: Constantin Herold via pve-devel @ 2025-09-23 17:40 UTC (permalink / raw)
  To: pve-devel; +Cc: Constantin Herold

[-- Attachment #1: Type: message/rfc822, Size: 4862 bytes --]

From: Constantin Herold <proxmox8914@herold.me>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-manager 0/1] feat: pass backup status to hook script on job-end/job-abort
Date: Tue, 23 Sep 2025 19:40:06 +0200
Message-ID: <20250923174007.84121-1-proxmox8914@herold.me>

I've been using the pve manager vzdump hook to do custom things after a backup is done e.g. backup some more files, call a webhook for monitoring, etc.

However there is currently a big drawback, the job state does not get passed, so there is no way to tell whether the backup was succesfull or not.

I recently had some drive issues which resulted in 1 vm backup failing, if i had not checked the mailnotification i would have never catched that.


e.g. /etc/vzdump.conf with `script: /root/backuphook.sh`

cat << 'EOF' > /root/backuphook
#!/bin/bash

cd /tmp
DATE=$(date +"%d.%m.%Y")
FILENAME="backup_$DATE.env"
echo "" >> "$FILENAME"
chmod 700 "$FILENAME"
echo "Arguments: $@" >> "$FILENAME"
printenv >> "$FILENAME"
echo -e "\n\n" >> "$FILENAME"
EOF


all the backuphook gets passed is the following:
```
Arguments: job-end  
PWD=/tmp
LVM_SUPPRESS_FD_WARNINGS=1
SHLVL=1
STOREID=backup
LC_ALL=C
OLDPWD=/
_=/usr/bin/printenv
```

No way to tell whether the backup was succesfull, can't even grep the backup log for it etc.

I've been using this simple patch to pass the errcount to the `job-end` and `job-abort` stage

This way you can check now if it was succesfull or not, e.g:

cat << 'EOF' > /root/backuphook
#!/bin/bash

if [[ "$*" != *job-end* ]]; then
    exit 0
fi

if [ "$ERRCOUNT" -gt 0 ]; then
    # alert on broken backup (could be drive issues etc.)
    # call webhook / trigger monitoring alert
else
    # do some more things after succesfull backup
fi
EOF


Would be great if this could be merged.

Best regards
Constantin


Constantin Herold (1):
  feat: pass backup status to hook script on job-end/job-abort

 PVE/VZDump.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

-- 
2.51.0



[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-24  9:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20250923174007.84121-1-proxmox8914@herold.me>
2025-09-23 17:40 ` [pve-devel] [PATCH pve-manager 1/1] feat: pass backup status to hook script on job-end/job-abort Constantin Herold via pve-devel
2025-09-24  9:40 ` [pve-devel] [PATCH pve-manager 0/1] " Thomas Lamprecht
2025-09-23 17:40 Constantin Herold via pve-devel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal