Created
March 13, 2021 07:22
-
-
Save kadrim/a5bc6c3c65a4fd577727140acca20e6f to your computer and use it in GitHub Desktop.
Proxmox modified vzdump-hook script, disable l2arc before backup and reenable it afterwards so not to trash the cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# modified hook script, disable l2arc before backup and reenable it afterwards so not to trash the cache | |
use strict; | |
print "HOOK: " . join (' ', @ARGV) . "\n"; | |
my $phase = shift; | |
if ($phase eq 'job-start' || | |
$phase eq 'job-end' || | |
$phase eq 'job-abort') { | |
# dumpdir is not available with all backup-methods | |
my $dumpdir = $ENV{DUMPDIR}; | |
# set the variable to empty string if it is undefined | |
$dumpdir //= ""; | |
my $storeid = $ENV{STOREID}; | |
print "HOOK-ENV: dumpdir=$dumpdir;storeid=$storeid\n"; | |
# flush zfs async-memory before backup | |
if ($phase eq 'job-start') { | |
print "HOOK-ENV: ZFS disabling L2ARC ...\n"; | |
system ("/sbin/zfs set secondarycache=none rpool") == 0 || | |
die "zfs L2ARC disable failed!"; | |
} | |
# flush zfs async-memory after backup | |
if ($phase eq 'job-end') { | |
print "HOOK-ENV: ZFS enabling L2ARC ...\n"; | |
system ("/sbin/zfs set secondarycache=all rpool") == 0 || | |
die "zfs L2ARC enable 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}; # openvz/qemu | |
# dumpdir is not available with all backup-methods | |
my $dumpdir = $ENV{DUMPDIR}; | |
# set the variable to empty string if it is undefined | |
$dumpdir //= ""; | |
my $storeid = $ENV{STOREID}; | |
my $hostname = $ENV{HOSTNAME}; | |
# tarfile is only available in phase 'backup-end' | |
my $tarfile = $ENV{TARFILE}; | |
# set the variable to empty string if it is undefined | |
$tarfile //= ""; | |
# logfile is only available in phase 'log-end' | |
my $logfile = $ENV{LOGFILE}; | |
# set the variable to empty string if it is undefined | |
$logfile //= ""; | |
print "HOOK-ENV: vmtype=$vmtype;dumpdir=$dumpdir;storeid=$storeid;hostname=$hostname;tarfile=$tarfile;logfile=$logfile\n"; | |
} else { | |
die "vzdump-hook-script.pl: got unknown phase '$phase'"; | |
} | |
exit (0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
modify line 27 and line 34 to match your system.
activate the hook-script by default by editing the file
/etc/vzdump.conf
and adjusting thescript
parameter