]> git.proxmox.com Git - pve-manager.git/commitdiff
add vzdump-hook-script.pl script to examples
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 31 Oct 2011 06:10:59 +0000 (07:10 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 31 Oct 2011 06:10:59 +0000 (07:10 +0100)
Makefile
bin/vzdump
vzdump-hook-script.pl [new file with mode: 0755]

index 67d4ecbcd1abb4fc351a6f95634d88472877109a..18dae5d2688f55bbfa03fdb78477e4885c1393de 100644 (file)
--- 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
 
index 196134a883a3b01cf12033ff68d9a7acb1c9c52f..64ee834e70c77ccc1ae02baa9dfd958bba44e03d 100755 (executable)
@@ -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<hook-script.pl>). 
+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<vzdump-hook-script.pl>). 
 
 =head1 EXCLUSIONS (OpenVZ only)
 
diff --git a/vzdump-hook-script.pl b/vzdump-hook-script.pl
new file mode 100755 (executable)
index 0000000..27075dc
--- /dev/null
@@ -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);