]>
Commit | Line | Data |
---|---|---|
9ff497a9 DM |
1 | #!/usr/bin/perl -w |
2 | ||
85cf35f8 HR |
3 | # Example hook script for vzdump (--script option) |
4 | # This can also be added as a line in /etc/vzdump.conf | |
5 | # e.g. 'script: /usr/local/bin/vzdump-hook-script.pl' | |
6 | ||
9ff497a9 DM |
7 | |
8 | use strict; | |
9 | ||
10 | print "HOOK: " . join (' ', @ARGV) . "\n"; | |
11 | ||
12 | my $phase = shift; | |
13 | ||
b241deb7 FE |
14 | if ($phase eq 'job-init' || |
15 | $phase eq 'job-start' || | |
cf24dc48 HR |
16 | $phase eq 'job-end' || |
17 | $phase eq 'job-abort') { | |
9ff497a9 | 18 | |
536ba932 | 19 | # undef for Proxmox Backup Server storages |
b241deb7 | 20 | # undef in phase 'job-init' except when --dumpdir is used directly |
28272ca2 DM |
21 | my $dumpdir = $ENV{DUMPDIR}; |
22 | ||
536ba932 | 23 | # undef when --dumpdir is used directly |
28272ca2 DM |
24 | my $storeid = $ENV{STOREID}; |
25 | ||
536ba932 FE |
26 | print "HOOK-ENV: "; |
27 | print "dumpdir=$dumpdir;" if defined($dumpdir); | |
28 | print "storeid=$storeid;" if defined($storeid); | |
29 | print "\n"; | |
28272ca2 | 30 | |
b241deb7 FE |
31 | # example: wake up remote storage node and enable storage |
32 | if ($phase eq 'job-init') { | |
33 | #system("wakeonlan AA:BB:CC:DD:EE:FF"); | |
34 | #sleep(30); | |
35 | #system ("/sbin/pvesm set $storeid --disable 0") == 0 || | |
36 | # die "enabling storage $storeid failed"; | |
37 | } | |
38 | ||
cf24dc48 | 39 | # do what you want |
9ff497a9 | 40 | |
cf24dc48 | 41 | } elsif ($phase eq 'backup-start' || |
9ff497a9 | 42 | $phase eq 'backup-end' || |
cf24dc48 HR |
43 | $phase eq 'backup-abort' || |
44 | $phase eq 'log-end' || | |
9ff497a9 | 45 | $phase eq 'pre-stop' || |
d5047243 FG |
46 | $phase eq 'pre-restart' || |
47 | $phase eq 'post-restart') { | |
9ff497a9 DM |
48 | |
49 | my $mode = shift; # stop/suspend/snapshot | |
50 | ||
51 | my $vmid = shift; | |
52 | ||
971e4bb1 | 53 | my $vmtype = $ENV{VMTYPE}; # lxc/qemu |
9ff497a9 | 54 | |
536ba932 | 55 | # undef for Proxmox Backup Server storages |
9ff497a9 DM |
56 | my $dumpdir = $ENV{DUMPDIR}; |
57 | ||
536ba932 | 58 | # undef when --dumpdir is used directly |
ff00abe6 LU |
59 | my $storeid = $ENV{STOREID}; |
60 | ||
9ff497a9 DM |
61 | my $hostname = $ENV{HOSTNAME}; |
62 | ||
88e7600d SI |
63 | # target is only available in phase 'backup-end' |
64 | my $target = $ENV{TARGET}; | |
9ff497a9 DM |
65 | |
66 | # logfile is only available in phase 'log-end' | |
536ba932 | 67 | # undef for Proxmox Backup Server storages |
cf24dc48 | 68 | my $logfile = $ENV{LOGFILE}; |
9ff497a9 | 69 | |
536ba932 FE |
70 | print "HOOK-ENV: "; |
71 | for my $var (qw(vmtype dumpdir storeid hostname target logfile)) { | |
72 | print "$var=$ENV{uc($var)};" if defined($ENV{uc($var)}); | |
73 | } | |
74 | print "\n"; | |
9ff497a9 DM |
75 | |
76 | # example: copy resulting backup file to another host using scp | |
77 | if ($phase eq 'backup-end') { | |
88e7600d | 78 | #system ("scp $target backup-host:/backup-dir") == 0 || |
cf24dc48 | 79 | # die "copy tar file to backup-host failed"; |
9ff497a9 DM |
80 | } |
81 | ||
82 | # example: copy resulting log file to another host using scp | |
83 | if ($phase eq 'log-end') { | |
cf24dc48 HR |
84 | #system ("scp $logfile backup-host:/backup-dir") == 0 || |
85 | # die "copy log file to backup-host failed"; | |
9ff497a9 | 86 | } |
cf24dc48 | 87 | |
9ff497a9 DM |
88 | } else { |
89 | ||
90 | die "got unknown phase '$phase'"; | |
91 | ||
92 | } | |
93 | ||
94 | exit (0); |