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