diff --git a/proxmox/vzdump-hook-lxc-template.pl b/proxmox/vzdump-hook-lxc-jessie-template.pl similarity index 76% rename from proxmox/vzdump-hook-lxc-template.pl rename to proxmox/vzdump-hook-lxc-jessie-template.pl index a4b978e..9bf0703 100755 --- a/proxmox/vzdump-hook-lxc-template.pl +++ b/proxmox/vzdump-hook-lxc-jessie-template.pl @@ -4,6 +4,8 @@ # Template directory my $TEMPLATE_DIR = "/mnt/zfsbkp/template/cache"; +# Template file name +my $TEMPLATE_FILE_LINK = "jessie.template.ipr.univ-rennes1.fr.tar.gz" # Number of template to keep available my $RETENTION_TIME = "2"; @@ -55,12 +57,21 @@ if ($phase eq 'job-start' || # 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"; + + # Unlink (eg hostname=jessietpl.ipr.univ-rennes1.fr) + system ("unlink $TEMPLATE_DIR/$TEMPLATE_FILE_LINK") + # no die cause if the previous backup exit on tarfile copy, the link might not exist + + # Link last template file to a better name + system ("find $TEMPLATE_DIR -iname 'vzdump-lxc-$vmid*.tar.*' -mmin -60 -exec ln -s {} $TEMPLATE_DIR/$TEMPLATE_FILE_LINK \;") == 0 || + die "link template to a better name failed"; + + # 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"; } } else {