vzdump - append vm hostname to dump file

  • Thread starter Thread starter mihait
  • Start date Start date
M

mihait

Guest
Hi,

I have a couple of pve boxes into a cluster and the backups(vzdumps) are going to a file server. The only problem with this setup is that is very hard to track a vm backup if you don't know the vm id ( and you need to find the dump quickly)

I have modified vzdump to append the hostname of the dumped vm to the output file. The option is called --savehostname

This is what I have modified:

proxmox_m1:/# diff /usr/sbin/vzdump /usr/sbin/alter.vzdump
52a53,55
> my $opt_savehostname;
>
>
422c425,428
< print STDERR "\t--restore FILENAME\trestore FILENAME\n";
---
> print STDERR "\t--restore FILENAME\trestore FILENAME\n\n";
>
> print STDERR "\t--savehostname \t\tappend VM hostname after the VMID\n";
>
1103c1109,1110
< 'dumpdir=s' => \$opt_dumpdir)) {
---
> 'dumpdir=s' => \$opt_dumpdir,
> 'savehostname'=> \$opt_savehostname)) {
1288c1295
<
---
>
1289a1297,1302
>
> if ($opt_savehostname) {
> $basename = $basename."-".$vmlist->{$vpsid}->{hostname};
>
> }
>

Hope that's usefull to others!

~Mihai
 
FOR PVE 1.3

I have changed the option name to --appendhostname and patched the web interface to globally select this option per backup job.

The modified files and modifications are listed below:

Code:
--- /usr/sbin/vzdump.orig       2009-05-29 12:14:21.000000000 +0300
+++ /usr/sbin/vzdump    2009-09-11 13:42:53.000000000 +0300
@@ -50,6 +50,9 @@
 my $opt_stopwait;
 my $opt_snapsize;
 my $opt_stdexcludes;
+my $opt_appendhostname;
+
+

 my $stopmode = '';

@@ -419,7 +422,10 @@
     print STDERR "\t--stopwait MINUTES\tmaximal time to wait until a VM is stopped\n";
     print STDERR "\t--bwlimit KBPS\t\tlimit I/O bandwidth; KBytes per second\n\n";

-    print STDERR "\t--restore FILENAME\trestore FILENAME\n";
+    print STDERR "\t--restore FILENAME\trestore FILENAME\n\n";
+
+    print STDERR "\t--appendhostname \t\tappend hostname after VMID\n";
+

     print STDERR "\n";
 }
@@ -1100,7 +1106,8 @@
                 'lockwait=i' => \$opt_lockwait,
                 'stopwait=i' => \$opt_stopwait,
                 'tmpdir=s' => \$opt_tmpdir,
-                'dumpdir=s' => \$opt_dumpdir)) {
+                'dumpdir=s' => \$opt_dumpdir,
+                'appendhostname'=> \$opt_appendhostname)) {
     print_usage ();
     exit (-1);
 }
@@ -1285,8 +1292,9 @@
        my $logfd;

        my $vmstarttime = time ();
-
-       my $basename = "vzdump-${vpsid}";
+
+       my $basename = "vzdump-${vpsid}". ($opt_appendhostname ? '-'.$vmlist->{$vpsid}->{hostname} : '');
+
        my $tarfile = $res->{tarfile} = "$dumpdir/$basename". ($opt_compress ? '.tgz' : '.tar');
        my $logfile = "$dumpdir/$basename.log";
Code:
--- /usr/share/pve-manager/root/backup/index.htm.orig   2009-09-11 13:44:43.000000000 +0300
+++ /usr/share/pve-manager/root/backup/index.htm        2009-09-11 13:38:10.000000000 +0300
@@ -79,6 +79,8 @@
      }

      $d->{compress} = $fdat{compress};
+###added by mihait
+     $d->{appendhostname} = $fdat{appendhostname};

      $d->{mailto} = $fdat{mailto};

@@ -113,6 +115,8 @@
            minute => 0,
            mode => 'snapshot',
            compress => 0,
+           ###added by mihait
+           appendhostname => 0,
            dow => "mon tue wed thu fri sat sun",
            node => $cinfo->{local}->{cid},
            dumpdir => '/backup',
@@ -139,6 +143,10 @@
    if (!defined ($fdat{compress})) {
      $fdat{compress} = $d->{compress};
    }
+   ###added by mihait
+   if (!defined ($fdat{appendhostname})) {
+     $fdat{appendhostname} = $d->{appendhostname};
+   }
    if (!defined ($fdat{mailto})) {
      $fdat{mailto} = $d->{mailto};
    }
@@ -188,6 +196,11 @@
    $grid->add_row (__("Compress files") . ':',
                   $form->create_element ('compress', 'bool', $fdat{compress}));

+###added by mihait
+   $grid->add_row (__("Append hostname") . ':',
+                  $form->create_element ('appendhostname', 'bool', $fdat{appendhostname}));
+
+

    my $html = $grid->html();
Code:
 diff -u /usr/share/perl5/PVE/Config.pm.orig   /usr/share/perl5/PVE/Config.pm
--- /usr/share/perl5/PVE/Config.pm.orig 2009-09-11 13:53:16.000000000 +0300
+++ /usr/share/perl5/PVE/Config.pm      2009-09-11 12:24:31.000000000 +0300
@@ -944,10 +944,13 @@
                my $opt_snap;
                my $opt_node;
                my $opt_quiet;
+               my $opt_appendhostname = 0;

                local @ARGV = split /\s+/, $param;
                if (!GetOptions ('all' => \$opt_all,
                                 'compress' => \$opt_compress,
+                                ##append hostname
+                                'appendhostname' => \$opt_appendhostname,
                                 'mailto=s@' => \$opt_mailto,
                                 'stop' =>\$opt_stop,
                                 'suspend' =>\$opt_suspend,
@@ -967,6 +970,8 @@
                    }

                    $d->{compress} = $opt_compress;
+                   ##added by mihait
+                   $d->{appendhostname} = $opt_appendhostname;
                    $d->{dumpdir} = $opt_dumpdir;
                    $d->{includeall} = $opt_all;
                    $d->{mailto} = $opt_mailto ? join (' ', @$opt_mailto) : '';
@@ -1050,6 +1055,8 @@
        $param .= " --node $d->{node}" if $d->{node};
        $param .= " --$d->{mode}"       if $d->{mode};
        $param .= " --compress" if $d->{compress};
+       ##added by mihait
+       $param .= " --appendhostname" if $d->{appendhostname};
        $param .= " --dumpdir $d->{dumpdir}" if $d->{dumpdir};

        if (my $mailto = $d->{mailto}) {
Bear in mind to save your files before doing anything.

Your vzdump contab should look like this when the option is selected ( see the 1st entry):

Code:
 cat /etc/cron.d/vzdump
# Atomatically generated file - do not edit

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

00 02 * * 1,5         root vzdump --quiet --node 1 --snapshot --appendhostname --dumpdir /backup --mailto XXX@XXX.XXX --all
00 02 * * 2           root vzdump --quiet --node 1 --snapshot --dumpdir /backup --mailto XXX@XXX.XXX 222
You will need to restart pvedaemon in order to get it working.

Code:
/etc/init.d/pvedaemon restart
 

Attachments

  • append.png
    append.png
    17.8 KB · Views: 12
Last edited by a moderator:
The above is chinees to me, but will this nice option be incorporated in a future version of vzdump?
 
chinees translated

On the console issue the following commands:

cd /tmp
wget http://www.chrishonline.com/files/pve13bkname-patch.tar.gz
tar -zxvpf pve13bkname-patch.tar.gz
./pve13backup-hostname.sh
rm pve13backup-hostname.sh
rm -f pve13bkname-patch.tar.gz

And enjoy the fun!

NOTE: If you want, you can download and unzip the attached patch file and upload the extracted pve13bkname-patch.tar.gz file to your /tmp folder instead of the wget command above and run the rest of the commands on the console. Beware the ... in the wget link.
 

Attachments

Last edited:
Great, many thanks!