vzdump patch to support --appendhostname and ISO8601 datetime format

jamver

New Member
Jul 6, 2014
5
0
1
Australia
It's been done in PVE v1, but I haven't seen any patches for more recent releases or any alternative solutions, so here is a patch to append the VM hostname to the output files from vzdump and also uses ISO8601 datetime format. I hope it is of use to others too and something like this can be integrated into the core release.

Code:
# diff -U0 /usr/share/perl5/PVE/VZDump.pm{-orig,}
--- VZDump.pm-orig      2014-04-26 17:36:46.000000000 +1000
+++ VZDump.pm   2014-07-06 23:51:37.000000000 +1000
@@ -715,2 +714,0 @@
-       my $lt = localtime();
-
@@ -718,3 +716,10 @@
-       my $basename = sprintf "${bkname}-%04d_%02d_%02d-%02d_%02d_%02d", 
-       $lt->year + 1900, $lt->mon + 1, $lt->mday, 
-       $lt->hour, $lt->min, $lt->sec;
+
+       if ($opts->{appendhostname}) {
+           # force loading of plugin->prepare to inherit hostname from VZDump/OpenVZ.pm and VZDump/QemuServer.pm
+           $plugin->prepare ($task, $vmid, qw(snapshot));
+
+           # append hostname to ${bkname}
+           $bkname = "vzdump-$vmtype-$vmid-$task->{hostname}";
+       }
+
+       my $basename = "${bkname}-" . strftime("%Y%m%dT%H%M%S%z", CORE::localtime());
@@ -1194,0 +1200,6 @@
+    },
+    appendhostname => {
+       type => 'boolean',
+       description => "Append VM hostname after the VMID.",
+       optional => 1,
+       default => 0,
 
Thanks a lot for this patch. It would be a great benefit if the hostname could appear in the backup filename in the core proxmox. Could it be added there? In the ESXI backups there are stored config files as well. I think this could help in case of a huge disaster. Would it be possible to backup them automatically as well?
 

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!