2011-10-31 10:10:59 +04:00
#!/usr/bin/perl -w
2018-03-09 13:32:31 +03:00
# 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'
2011-10-31 10:10:59 +04:00
use strict ;
print "HOOK: " . join ( ' ' , @ ARGV ) . "\n" ;
my $ phase = shift ;
2022-01-18 11:21:14 +03:00
if ( $ phase eq 'job-init' ||
$ phase eq 'job-start' ||
2018-03-09 13:32:32 +03:00
$ phase eq 'job-end' ||
$ phase eq 'job-abort' ) {
2011-10-31 10:10:59 +04:00
2022-01-17 14:35:58 +03:00
# undef for Proxmox Backup Server storages
2022-01-18 11:21:14 +03:00
# undef in phase 'job-init' except when --dumpdir is used directly
2013-09-13 08:53:03 +04:00
my $ dumpdir = $ ENV { DUMPDIR } ;
2022-01-17 14:35:58 +03:00
# undef when --dumpdir is used directly
2013-09-13 08:53:03 +04:00
my $ storeid = $ ENV { STOREID } ;
2022-01-17 14:35:58 +03:00
print "HOOK-ENV: " ;
print "dumpdir=$dumpdir;" if defined ( $ dumpdir ) ;
print "storeid=$storeid;" if defined ( $ storeid ) ;
print "\n" ;
2013-09-13 08:53:03 +04:00
2022-01-18 11:21:14 +03:00
# 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";
}
2018-03-09 13:32:32 +03:00
# do what you want
2011-10-31 10:10:59 +04:00
2018-03-09 13:32:32 +03:00
} elsif ( $ phase eq 'backup-start' ||
2011-10-31 10:10:59 +04:00
$ phase eq 'backup-end' ||
2018-03-09 13:32:32 +03:00
$ phase eq 'backup-abort' ||
$ phase eq 'log-end' ||
2011-10-31 10:10:59 +04:00
$ phase eq 'pre-stop' ||
2016-04-22 11:35:29 +03:00
$ phase eq 'pre-restart' ||
$ phase eq 'post-restart' ) {
2011-10-31 10:10:59 +04:00
my $ mode = shift ; # stop/suspend/snapshot
my $ vmid = shift ;
2018-10-29 13:09:57 +03:00
my $ vmtype = $ ENV { VMTYPE } ; # lxc/qemu
2011-10-31 10:10:59 +04:00
2022-01-17 14:35:58 +03:00
# undef for Proxmox Backup Server storages
2011-10-31 10:10:59 +04:00
my $ dumpdir = $ ENV { DUMPDIR } ;
2022-01-17 14:35:58 +03:00
# undef when --dumpdir is used directly
2013-09-10 21:40:10 +04:00
my $ storeid = $ ENV { STOREID } ;
2011-10-31 10:10:59 +04:00
my $ hostname = $ ENV { HOSTNAME } ;
2020-07-14 11:09:18 +03:00
# target is only available in phase 'backup-end'
my $ target = $ ENV { TARGET } ;
2011-10-31 10:10:59 +04:00
# logfile is only available in phase 'log-end'
2022-01-17 14:35:58 +03:00
# undef for Proxmox Backup Server storages
2018-03-09 13:32:32 +03:00
my $ logfile = $ ENV { LOGFILE } ;
2011-10-31 10:10:59 +04:00
2022-01-17 14:35:58 +03:00
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" ;
2011-10-31 10:10:59 +04:00
# example: copy resulting backup file to another host using scp
if ( $ phase eq 'backup-end' ) {
2020-07-14 11:09:18 +03:00
#system ("scp $target backup-host:/backup-dir") == 0 ||
2018-03-09 13:32:32 +03:00
# die "copy tar file to backup-host failed";
2011-10-31 10:10:59 +04:00
}
# example: copy resulting log file to another host using scp
if ( $ phase eq 'log-end' ) {
2018-03-09 13:32:32 +03:00
#system ("scp $logfile backup-host:/backup-dir") == 0 ||
# die "copy log file to backup-host failed";
2011-10-31 10:10:59 +04:00
}
2018-03-09 13:32:32 +03:00
2011-10-31 10:10:59 +04:00
} else {
die "got unknown phase '$phase'" ;
}
exit ( 0 ) ;