all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH v2 manager 1/2] vzdump: example hook script: avoid undef warnings
@ 2022-01-17 11:35 Fabian Ebner
  2022-01-17 11:35 ` [pve-devel] [PATCH v2 manager 2/2] close #3476: vzdump: add job-init hook Fabian Ebner
  2022-01-17 15:32 ` [pve-devel] applied: [PATCH v2 manager 1/2] vzdump: example hook script: avoid undef warnings Fabian Grünbichler
  0 siblings, 2 replies; 5+ messages in thread
From: Fabian Ebner @ 2022-01-17 11:35 UTC (permalink / raw)
  To: pve-devel

Some environment variables are undef in certain scenarios.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

New in v2.

 vzdump-hook-script.pl | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/vzdump-hook-script.pl b/vzdump-hook-script.pl
index 1be440b3..60edbc04 100755
--- a/vzdump-hook-script.pl
+++ b/vzdump-hook-script.pl
@@ -15,11 +15,16 @@ if ($phase eq 'job-start' ||
     $phase eq 'job-end'  ||
     $phase eq 'job-abort') {
 
+    # undef for Proxmox Backup Server storages
     my $dumpdir = $ENV{DUMPDIR};
 
+    # undef when --dumpdir is used directly
     my $storeid = $ENV{STOREID};
 
-    print "HOOK-ENV: dumpdir=$dumpdir;storeid=$storeid\n";
+    print "HOOK-ENV: ";
+    print "dumpdir=$dumpdir;" if defined($dumpdir);
+    print "storeid=$storeid;" if defined($storeid);
+    print "\n";
 
     # do what you want
 
@@ -37,8 +42,10 @@ if ($phase eq 'job-start' ||
 
     my $vmtype = $ENV{VMTYPE}; # lxc/qemu
 
+    # undef for Proxmox Backup Server storages
     my $dumpdir = $ENV{DUMPDIR};
 
+    # undef when --dumpdir is used directly
     my $storeid = $ENV{STOREID};
 
     my $hostname = $ENV{HOSTNAME};
@@ -47,9 +54,14 @@ if ($phase eq 'job-start' ||
     my $target = $ENV{TARGET};
 
     # logfile is only available in phase 'log-end'
+    # undef for Proxmox Backup Server storages
     my $logfile = $ENV{LOGFILE};
 
-    print "HOOK-ENV: vmtype=$vmtype;dumpdir=$dumpdir;storeid=$storeid;hostname=$hostname;target=$target;logfile=$logfile\n";
+    print "HOOK-ENV: ";
+    for my $var (qw(vmtype dumpdir storeid hostname target logfile)) {
+	print "$var=$ENV{uc($var)};" if defined($ENV{uc($var)});
+    }
+    print "\n";
 
     # example: copy resulting backup file to another host using scp
     if ($phase eq 'backup-end') {
-- 
2.30.2





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

end of thread, other threads:[~2022-01-17 15:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-17 11:35 [pve-devel] [PATCH v2 manager 1/2] vzdump: example hook script: avoid undef warnings Fabian Ebner
2022-01-17 11:35 ` [pve-devel] [PATCH v2 manager 2/2] close #3476: vzdump: add job-init hook Fabian Ebner
2022-01-17 15:37   ` Fabian Grünbichler
2022-01-17 15:54     ` Thomas Lamprecht
2022-01-17 15:32 ` [pve-devel] applied: [PATCH v2 manager 1/2] vzdump: example hook script: avoid undef warnings Fabian Grünbichler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal