]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/perl -w | |
2 | ||
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 | ||
7 | ||
8 | use strict; | |
9 | ||
10 | print "HOOK: " . join (' ', @ARGV) . "\n"; | |
11 | ||
12 | my $phase = shift; | |
13 | ||
14 | if ($phase eq 'job-init' || | |
15 | $phase eq 'job-start' || | |
16 | $phase eq 'job-end' || | |
17 | $phase eq 'job-abort') { | |
18 | ||
19 | # undef for Proxmox Backup Server storages | |
20 | # undef in phase 'job-init' except when --dumpdir is used directly | |
21 | my $dumpdir = $ENV{DUMPDIR}; | |
22 | ||
23 | # undef when --dumpdir is used directly | |
24 | my $storeid = $ENV{STOREID}; | |
25 | ||
26 | print "HOOK-ENV: "; | |
27 | print "dumpdir=$dumpdir;" if defined($dumpdir); | |
28 | print "storeid=$storeid;" if defined($storeid); | |
29 | print "\n"; | |
30 | ||
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 | ||
39 | # do what you want | |
40 | ||
41 | } elsif ($phase eq 'backup-start' || | |
42 | $phase eq 'backup-end' || | |
43 | $phase eq 'backup-abort' || | |
44 | $phase eq 'log-end' || | |
45 | $phase eq 'pre-stop' || | |
46 | $phase eq 'pre-restart' || | |
47 | $phase eq 'post-restart') { | |
48 | ||
49 | my $mode = shift; # stop/suspend/snapshot | |
50 | ||
51 | my $vmid = shift; | |
52 | ||
53 | my $vmtype = $ENV{VMTYPE}; # lxc/qemu | |
54 | ||
55 | # undef for Proxmox Backup Server storages | |
56 | my $dumpdir = $ENV{DUMPDIR}; | |
57 | ||
58 | # undef when --dumpdir is used directly | |
59 | my $storeid = $ENV{STOREID}; | |
60 | ||
61 | my $hostname = $ENV{HOSTNAME}; | |
62 | ||
63 | # target is only available in phase 'backup-end' | |
64 | my $target = $ENV{TARGET}; | |
65 | ||
66 | # logfile is only available in phase 'log-end' | |
67 | # undef for Proxmox Backup Server storages | |
68 | my $logfile = $ENV{LOGFILE}; | |
69 | ||
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"; | |
75 | ||
76 | # example: copy resulting backup file to another host using scp | |
77 | if ($phase eq 'backup-end') { | |
78 | #system ("scp $target backup-host:/backup-dir") == 0 || | |
79 | # die "copy tar file to backup-host failed"; | |
80 | } | |
81 | ||
82 | # example: copy resulting log file to another host using scp | |
83 | if ($phase eq 'log-end') { | |
84 | #system ("scp $logfile backup-host:/backup-dir") == 0 || | |
85 | # die "copy log file to backup-host failed"; | |
86 | } | |
87 | ||
88 | } else { | |
89 | ||
90 | die "got unknown phase '$phase'"; | |
91 | ||
92 | } | |
93 | ||
94 | exit (0); |