]> git.proxmox.com Git - pve-manager.git/blob - vzdump-hook-script.pl
add vzdump-hook-script.pl script to examples
[pve-manager.git] / vzdump-hook-script.pl
1 #!/usr/bin/perl -w
2
3 # example hook script for vzdump (--script option)
4
5 use strict;
6
7 print "HOOK: " . join (' ', @ARGV) . "\n";
8
9 my $phase = shift;
10
11 if ($phase eq 'job-start' ||
12 $phase eq 'job-end' ||
13 $phase eq 'job-abort') {
14
15 # do what you want
16
17 } elsif ($phase eq 'backup-start' ||
18 $phase eq 'backup-end' ||
19 $phase eq 'backup-abort' ||
20 $phase eq 'log-end' ||
21 $phase eq 'pre-stop' ||
22 $phase eq 'pre-restart') {
23
24 my $mode = shift; # stop/suspend/snapshot
25
26 my $vmid = shift;
27
28 my $vmtype = $ENV{VMTYPE}; # openvz/qemu
29
30 my $dumpdir = $ENV{DUMPDIR};
31
32 my $hostname = $ENV{HOSTNAME};
33
34 # tarfile is only available in phase 'backup-end'
35 my $tarfile = $ENV{TARFILE};
36
37 # logfile is only available in phase 'log-end'
38 my $logfile = $ENV{LOGFILE};
39
40 print "HOOK-ENV: vmtype=$vmtype;dumpdir=$dumpdir;hostname=$hostname;tarfile=$tarfile;logfile=$logfile\n";
41
42 # example: copy resulting backup file to another host using scp
43 if ($phase eq 'backup-end') {
44 #system ("scp $tarfile backup-host:/backup-dir") == 0 ||
45 # die "copy tar file to backup-host failed";
46 }
47
48 # example: copy resulting log file to another host using scp
49 if ($phase eq 'log-end') {
50 #system ("scp $logfile backup-host:/backup-dir") == 0 ||
51 # die "copy log file to backup-host failed";
52 }
53
54 } else {
55
56 die "got unknown phase '$phase'";
57
58 }
59
60 exit (0);