add hostname to backup file name

I

ieldib

Guest
Hi All,

I am trying to add the CTID hostname (openvz containers) to the backup files that are created on these containers. I tried using a hookfile which had no effect while passing the --script hookfile.pl . Can anyone assist ? This is an annoying problem as a container that has CTID 110 can be retaken by a new container if that previous container is destroyed.


#!/usr/bin/perl -w


# example hook script for vzdump (--script option)


use strict;
use File::Copy qw(move);


my $basedir="/mnt/backups/";
print "HOOK: " . join (' ', @ARGV) . "\n";


my $phase = shift;
if ($phase eq 'backup-end' ){
my $mode = shift; # stop/suspend/snapshot
my $vmid = shift;
my $vmtype = $ENV{VMTYPE} if defined ($ENV{VMTYPE}); # openvz/qemu
my $dumpdir = $ENV{DUMPDIR} if defined ($ENV{DUMPDIR});
my $hostname = $ENV{HOSTNAME} if defined ($ENV{HOSTNAME});
# tarfile is only available in phase 'backup-end'
my $tarfile = $ENV{TARFILE} if defined ($ENV{TARFILE});
# logfile is only available in phase 'log-end'
my $logfile = $ENV{LOGFILE} if defined ($ENV{LOGFILE});
print "HOOK-ENV: vmtype=$vmtype;dumpdir=$dumpdir;hostname=$hostname;tarfile=$tarfile;logfile=$logfile\n";
if ($phase eq 'backup-end' and defined ($tarfile) and defined ($hostname)) {
if ( $tarfile=~/($basedir\/vzdump-(qemu|openvz)-\d+-)(\d\d\d\d_.+)/ ){
my $tarfile2=$1.$hostname."-".$3;
print "HOOK: Renaming file $tarfile to $tarfile2\n";
move $tarfile, $tarfile2;
}
}
}


exit (0);
 
I also want this function.
It will be very help to prpend hostname to backup file name.

Anyone could help us?
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!