]> git.proxmox.com Git - pve-manager.git/commitdiff
vzdump: example hook script: avoid undef warnings
authorFabian Ebner <f.ebner@proxmox.com>
Mon, 17 Jan 2022 11:35:58 +0000 (12:35 +0100)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Mon, 17 Jan 2022 15:30:51 +0000 (16:30 +0100)
Some environment variables are undef in certain scenarios.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
vzdump-hook-script.pl

index 1be440b3392ebee260436f5a678ded77fe66ddb5..60edbc0487b78aa96ffa7960fdcb300ccbe7f7d2 100755 (executable)
@@ -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') {