From 9ff497a9f45fb4767a09b3f9fa12915c9722d976 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 31 Oct 2011 07:10:59 +0100 Subject: [PATCH] add vzdump-hook-script.pl script to examples --- Makefile | 9 ++++--- bin/vzdump | 2 +- vzdump-hook-script.pl | 60 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 5 deletions(-) create mode 100755 vzdump-hook-script.pl diff --git a/Makefile b/Makefile index 67d4ecbc..18dae5d2 100644 --- a/Makefile +++ b/Makefile @@ -65,10 +65,10 @@ upload: ${DEB} # scp aplinfo/aplinfo.dat aplinfo.dat.gz aplinfo/aplinfo.dat.asc pve.proxmox.com:/home/ftp/appliances/ .PHONY: install -install: country.dat vznet.conf vzdump.conf +install: country.dat vznet.conf vzdump.conf vzdump-hook-script.pl install -d ${DESTDIR}/usr/share/${PACKAGE} install -d ${DESTDIR}/usr/share/man/man1 - install -d ${DESTDIR}/usr/share/doc/${PACKAGE} + install -d ${DOCDIR}/examples install -d ${DESTDIR}/var/lib/${PACKAGE} install -d ${DESTDIR}/var/lib/vz/images install -d ${DESTDIR}/var/lib/vz/template/cache @@ -76,8 +76,9 @@ install: country.dat vznet.conf vzdump.conf install -d ${DESTDIR}/var/lib/vz/template/qemu install -D -m 0644 vzdump.conf ${DESTDIR}/etc/vzdump.conf install -D -m 0755 vznet.conf ${DESTDIR}/etc/vz/vznet.conf - install -m 0644 copyright ${DESTDIR}/usr/share/doc/${PACKAGE} - install -m 0644 debian/changelog.Debian ${DESTDIR}/usr/share/doc/${PACKAGE} + install -m 0644 vzdump-hook-script.pl ${DOCDIR}/examples/vzdump-hook-script.pl + install -m 0644 copyright ${DOCDIR} + install -m 0644 debian/changelog.Debian ${DOCDIR} install -m 0644 country.dat ${DESTDIR}/usr/share/${PACKAGE} set -e && for i in ${SUBDIRS}; do ${MAKE} -C $$i $@; done diff --git a/bin/vzdump b/bin/vzdump index 196134a8..64ee834e 100755 --- a/bin/vzdump +++ b/bin/vzdump @@ -126,7 +126,7 @@ Global configuration is stored in /etc/vzdump.conf. =head1 HOOK SCRIPT -You can specify a hook script with option C<--script>. This script is called at various phases of the backup process, with parameters accordingly set. You can find an example in the documentation directory (C). +You can specify a hook script with option C<--script>. This script is called at various phases of the backup process, with parameters accordingly set. You can find an example in the documentation directory (C). =head1 EXCLUSIONS (OpenVZ only) diff --git a/vzdump-hook-script.pl b/vzdump-hook-script.pl new file mode 100755 index 00000000..27075dcc --- /dev/null +++ b/vzdump-hook-script.pl @@ -0,0 +1,60 @@ +#!/usr/bin/perl -w + +# example hook script for vzdump (--script option) + +use strict; + +print "HOOK: " . join (' ', @ARGV) . "\n"; + +my $phase = shift; + +if ($phase eq 'job-start' || + $phase eq 'job-end' || + $phase eq 'job-abort') { + + # 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') { + + my $mode = shift; # stop/suspend/snapshot + + my $vmid = shift; + + my $vmtype = $ENV{VMTYPE}; # openvz/qemu + + my $dumpdir = $ENV{DUMPDIR}; + + my $hostname = $ENV{HOSTNAME}; + + # tarfile is only available in phase 'backup-end' + my $tarfile = $ENV{TARFILE}; + + # logfile is only available in phase 'log-end' + my $logfile = $ENV{LOGFILE}; + + print "HOOK-ENV: vmtype=$vmtype;dumpdir=$dumpdir;hostname=$hostname;tarfile=$tarfile;logfile=$logfile\n"; + + # example: copy resulting backup file to another host using scp + if ($phase eq 'backup-end') { + #system ("scp $tarfile 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); -- 2.39.5