Add proxmox hook to copy a dump as a template
This commit is contained in:
parent
4b73c35d9e
commit
999bc04056
37
README.md
37
README.md
|
@ -1,7 +1,42 @@
|
||||||
|
# ipr_scripts
|
||||||
|
|
||||||
* grav_cron_: A daily cron to check if [grav website][Grav] got available updates.
|
#### Table of Contents
|
||||||
|
|
||||||
|
1. [Overview](#overview)
|
||||||
|
2. [Scripts](#scripts)
|
||||||
|
* [Proxmox](#proxmox)
|
||||||
|
* [Grav](#grav)
|
||||||
|
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
Some usefull scripts for admin or users.
|
||||||
|
|
||||||
|
## Scripts
|
||||||
|
|
||||||
|
### Proxmox
|
||||||
|
|
||||||
|
#### vzdump-hook-lxc-template.pl
|
||||||
|
|
||||||
|
This script must be used as a vzdump's hook (the backup utility for CT and VMs for Proxmox).
|
||||||
|
|
||||||
|
1. The script will :
|
||||||
|
* Remove the templates oldest than 2 days (by default).
|
||||||
|
* Copy the current dump as a template in **/mnt/zfsbkp/template/cache** (by default).
|
||||||
|
2. How-to use :
|
||||||
|
* Define a backup as usual (in the Proxmox's webgui) and prefer to select only one container.
|
||||||
|
* In command on the hypervisor, open **/etc/pve/vzdump.cron** and edit the line of the new dump to add : **--script /usr/local/bin/vzdump-hook-lxc-template.pl**.
|
||||||
|
3. Customization :
|
||||||
|
* If you don't store template in the default path (**/mnt/zfsbkp/template/cache**), please edit the variable **$TEMPLATE_DIR** in the script.
|
||||||
|
|
||||||
|
|
||||||
|
### Grav
|
||||||
|
|
||||||
|
#### grav_cron
|
||||||
|
A daily cron to check if [Grav][grav website] got available updates.
|
||||||
* It need to work from the Grav's root directory.
|
* It need to work from the Grav's root directory.
|
||||||
* If an update is available, it will create a empty file (${GRAV_ROOT}/logs/update), else it will ensure the "update" file is removed.
|
* If an update is available, it will create a empty file (${GRAV_ROOT}/logs/update), else it will ensure the "update" file is removed.
|
||||||
|
* Be sure to monitore if **${GRAV_ROOT}/logs/update** exist.
|
||||||
|
|
||||||
|
|
||||||
[grav website]: https://getgrav.org/
|
[grav website]: https://getgrav.org/
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
#!/usr/bin/perl -w
|
||||||
|
|
||||||
|
# hook script to copy a dump as a new LXC template (with --script option)
|
||||||
|
|
||||||
|
# Template directory
|
||||||
|
my $TEMPLATE_DIR = "/mnt/zfsbkp/template/cache";
|
||||||
|
# Number of template to keep available
|
||||||
|
my $RETENTION_TIME = "2";
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
print "HOOK: " . join (' ', @ARGV) . "\n";
|
||||||
|
|
||||||
|
my $phase = shift;
|
||||||
|
|
||||||
|
if ($phase eq 'job-start' ||
|
||||||
|
$phase eq 'job-end' ||
|
||||||
|
$phase eq 'job-abort') {
|
||||||
|
|
||||||
|
my $dumpdir = $ENV{DUMPDIR};
|
||||||
|
|
||||||
|
my $storeid = $ENV{STOREID};
|
||||||
|
|
||||||
|
print "HOOK-ENV: dumpdir=$dumpdir;storeid=$storeid\n";
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
my $dumpdir = $ENV{DUMPDIR};
|
||||||
|
|
||||||
|
my $storeid = $ENV{STOREID};
|
||||||
|
|
||||||
|
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;vmid=$vmid;dumpdir=$dumpdir;storeid=$storeid;hostname=$hostname;tarfile=$tarfile;logfile=$logfile\n";
|
||||||
|
|
||||||
|
# copy resulting backup file as a template
|
||||||
|
if ($phase eq 'backup-end') {
|
||||||
|
# Ensure to remove template older than $RETENTION_TIME
|
||||||
|
system ("find $TEMPLATE_DIR -iname 'vzdump-lxc-$vmid*.tar.*' -mtime +$RETENTION_TIME -delete ") == 0 ||
|
||||||
|
die "remove oldest template failed";
|
||||||
|
# Copy the dump as a LXC template
|
||||||
|
system ("cp -- $tarfile $TEMPLATE_DIR") == 0 ||
|
||||||
|
die "copy tar file as a template failed";
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
die "got unknown phase '$phase'";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
exit (0);
|
Loading…
Reference in New Issue