]> git.proxmox.com Git - pve-manager.git/blobdiff - PVE/VZDump.pm
VZDump: mark 'size' as deprecated, warn if set
[pve-manager.git] / PVE / VZDump.pm
index 218b033f1d0b074586e862b3f29bb2658510da82..0b4f9923284982d95d3472bce6683272b791906f 100644 (file)
@@ -32,7 +32,7 @@ my @plugins = qw();
 my $confdesc = {
     vmid => {
        type => 'string', format => 'pve-vmid-list',
-       description => "The ID of the VM you want to backup.",
+       description => "The ID of the guest system you want to backup.",
        completion => \&PVE::Cluster::complete_local_vmid,
        optional => 1,
     },
@@ -43,13 +43,13 @@ my $confdesc = {
     }),
     all => {
        type => 'boolean',
-       description => "Backup all known VMs on this host.",
+       description => "Backup all known guest systems on this host.",
        optional => 1,
        default => 0,
     },
     stdexcludes => {
        type => 'boolean',
-       description => "Exclude temorary files and logs.",
+       description => "Exclude temporary files and logs.",
        optional => 1,
        default => 1,
     },
@@ -58,11 +58,11 @@ my $confdesc = {
        description => "Compress dump file.",
        optional => 1,
        enum => ['0', '1', 'gzip', 'lzo'],
-       default => 'lzo',
+       default => '0',
     },
     pigz=> {
        type => "integer",
-       description => "Uses pigz instead of gzip when N>0.".
+       description => "Use pigz instead of gzip when N>0.".
            " N=1 uses half of cores, N>1 uses N as thread count.",
        optional => 1,
        default => 0,
@@ -77,17 +77,17 @@ my $confdesc = {
        type => 'string',
        description => "Backup mode.",
        optional => 1,
-       default => 'stop',
+       default => 'snapshot',
        enum => [ 'snapshot', 'suspend', 'stop' ],
     },
     exclude => {
        type => 'string', format => 'pve-vmid-list',
-       description => "exclude specified VMs (assumes --all)",
+       description => "Exclude specified guest systems (assumes --all)",
        optional => 1,
     },
     'exclude-path' => {
        type => 'string', format => 'string-alist',
-       description => "exclude certain files/directories (shell globs).",
+       description => "Exclude certain files/directories (shell globs).",
        optional => 1,
     },
     mailto => {
@@ -130,15 +130,17 @@ my $confdesc = {
     },
     size => {
        type => 'integer',
-       description => "LVM snapshot size in MB.",
+       description => "Unused, will be removed in a future release.",
        optional => 1,
        minimum => 500,
+       default => 1024,
     },
     bwlimit => {
        type => 'integer',
        description => "Limit I/O bandwidth (KBytes per second).",
        optional => 1,
        minimum => 0,
+       default => 0,
     },
     ionice => {
        type => 'integer',
@@ -146,24 +148,28 @@ my $confdesc = {
        optional => 1,
        minimum => 0,
        maximum => 8,
+       default => 7,
     },
     lockwait => {
        type => 'integer',
        description => "Maximal time to wait for the global lock (minutes).",
        optional => 1,
        minimum => 0,
+       default => 3*60, # 3 hours
     },
     stopwait => {
        type => 'integer',
-       description => "Maximal time to wait until a VM is stopped (minutes).",
+       description => "Maximal time to wait until a guest system is stopped (minutes).",
        optional => 1,
        minimum => 0,
+       default => 10, # 10 minutes
     },
     maxfiles => {
        type => 'integer',
-       description => "Maximal number of backup files per VM.",
+       description => "Maximal number of backup files per guest system.",
        optional => 1,
        minimum => 1,
+       default => 1,
     },
     remove => {
        type => 'boolean',
@@ -230,7 +236,7 @@ sub run_command {
 sub storage_info {
     my $storage = shift;
 
-    my $cfg = cfs_read_file('storage.cfg');
+    my $cfg = PVE::Storage::config();
     my $scfg = PVE::Storage::storage_config($cfg, $storage);
     my $type = $scfg->{type};
  
@@ -328,14 +334,10 @@ sub read_vzdump_defaults {
     my $fn = "/etc/vzdump.conf";
 
     my $defaults = {
-       bwlimit => 0,
-       ionice => 7,
-       size => 1024,
-       lockwait => 3*60, # 3 hours
-       stopwait => 10, # 10 minutes
-       mode => 'snapshot',
-       maxfiles => 1, 
-       pigz => 0,
+       map {
+           my $default = $confdesc->{$_}->{default};
+            defined($default) ? ($_ => $default) : ()
+       } keys %$confdesc
     };
 
     my $raw;
@@ -349,7 +351,7 @@ sub read_vzdump_defaults {
     }
 
     foreach my $key (keys %$defaults) {
-       $res->{$key} = $defaults->{$key} if !$res->{$key};
+       $res->{$key} = $defaults->{$key} if !defined($res->{$key});
     }
 
     return $res;
@@ -389,91 +391,45 @@ sub sendmail {
     my $hostname = `hostname -f` || PVE::INotify::nodename();
     chomp $hostname;
 
-    my $boundary = "----_=_NextPart_001_".int(time).$$;
-
-    my $rcvrarg = '';
-    foreach my $r (@$mailto) {
-       $rcvrarg .= " '$r'";
-    }
-    my $dcconf = PVE::Cluster::cfs_read_file('datacenter.cfg');
-    my $mailfrom = $dcconf->{email_from} || "root";
-
-    open (MAIL,"|sendmail -B 8BITMIME -f $mailfrom $rcvrarg") || 
-       die "unable to open 'sendmail' - $!";
-
-    my $rcvrtxt = join (', ', @$mailto);
-
-    print MAIL "Content-Type: multipart/alternative;\n";
-    print MAIL "\tboundary=\"$boundary\"\n";
-    print MAIL "MIME-Version: 1.0\n";
-
-    print MAIL "FROM: vzdump backup tool <$mailfrom>\n";
-    print MAIL "TO: $rcvrtxt\n";
-    print MAIL "SUBJECT: vzdump backup status ($hostname) : $stat\n";
-    print MAIL "\n";
-    print MAIL "This is a multi-part message in MIME format.\n\n";
-    print MAIL "--$boundary\n";
-
-    print MAIL "Content-Type: text/plain;\n";
-    print MAIL "\tcharset=\"UTF8\"\n";
-    print MAIL "Content-Transfer-Encoding: 8bit\n";
-    print MAIL "\n";
-
     # text part
-
-    my $fill = '  '; # Avoid The Remove Extra Line Breaks Issue (MS Outlook)
-
-    print MAIL sprintf ("${fill}%-10s %-6s %10s %10s  %s\n", qw(VMID STATUS TIME SIZE FILENAME));
+    my $text = sprintf ("%-10s %-6s %10s %10s  %s\n", qw(VMID STATUS TIME SIZE FILENAME));
     foreach my $task (@$tasklist) {
        my $vmid = $task->{vmid};
        if  ($task->{state} eq 'ok') {
 
-           print MAIL sprintf ("${fill}%-10s %-6s %10s %10s  %s\n", $vmid, 
-                               $task->{state}, 
+           $text .= sprintf ("%-10s %-6s %10s %10s  %s\n", $vmid,
+                               $task->{state},
                                format_time($task->{backuptime}),
                                format_size ($task->{size}),
                                $task->{tarfile});
        } else {
-           print MAIL sprintf ("${fill}%-10s %-6s %10s %8.2fMB  %s\n", $vmid, 
-                               $task->{state}, 
+           $text .= sprintf ("%-10s %-6s %10s %8.2fMB  %s\n", $vmid,
+                               $task->{state},
                                format_time($task->{backuptime}),
                                0, '-');
        }
     }
-    print MAIL "${fill}\n";
-    print MAIL "${fill}Detailed backup logs:\n";
-    print MAIL "${fill}\n";
-    print MAIL "$fill$cmdline\n";
-    print MAIL "${fill}\n";
+
+    $text .= "Detailed backup logs:\n\n";
+    $text .= "$cmdline\n\n";
 
     foreach my $task (@$tasklist) {
        my $vmid = $task->{vmid};
        my $log = $task->{tmplog};
        if (!$log) {
-           print MAIL "${fill}$vmid: no log available\n\n";
+           $text .= "$vmid: no log available\n\n";
            next;
        }
        open (TMP, "$log");
-       while (my $line = <TMP>) { print MAIL encode8bit ("${fill}$vmid: $line"); }
+       while (my $line = <TMP>) { $text .= encode8bit ("$vmid: $line"); }
        close (TMP);
-       print MAIL "${fill}\n";
+       $text .= "\n";
     }
 
-    # end text part
-    print MAIL "\n--$boundary\n";
-
-    print MAIL "Content-Type: text/html;\n";
-    print MAIL "\tcharset=\"UTF8\"\n";
-    print MAIL "Content-Transfer-Encoding: 8bit\n";
-    print MAIL "\n";
-
     # html part
-
-    print MAIL "<html><body>\n";
-
-    print MAIL "<table border=1 cellpadding=3>\n";
-
-    print MAIL "<tr><td>VMID<td>NAME<td>STATUS<td>TIME<td>SIZE<td>FILENAME</tr>\n";
+    my $html = "<html><body>\n";
+    $html .= "<table border=1 cellpadding=3>\n";
+    $html .= "<tr><td>VMID<td>NAME<td>STATUS<td>TIME<td>SIZE<td>FILENAME</tr>\n";
 
     my $ssize = 0;
 
@@ -485,56 +441,54 @@ sub sendmail {
 
            $ssize += $task->{size};
 
-           print MAIL sprintf ("<tr><td>%s<td>%s<td>OK<td>%s<td align=right>%s<td>%s</tr>\n", 
+           $html .= sprintf ("<tr><td>%s<td>%s<td>OK<td>%s<td align=right>%s<td>%s</tr>\n",
                                $vmid, $name,
                                format_time($task->{backuptime}),
                                format_size ($task->{size}),
                                escape_html ($task->{tarfile}));
        } else {
-           print MAIL sprintf ("<tr><td>%s<td>%s<td><font color=red>FAILED<td>%s<td colspan=2>%s</tr>\n",
-                               $vmid, $name, format_time($task->{backuptime}), 
+           $html .= sprintf ("<tr><td>%s<td>%s<td><font color=red>FAILED<td>%s<td colspan=2>%s</tr>\n",
+                               $vmid, $name, format_time($task->{backuptime}),
                                escape_html ($task->{msg}));
        }
     }
 
-    print MAIL sprintf ("<tr><td align=left colspan=3>TOTAL<td>%s<td>%s<td></tr>",
+    $html .= sprintf ("<tr><td align=left colspan=3>TOTAL<td>%s<td>%s<td></tr>",
  format_time ($totaltime), format_size ($ssize));
 
-    print MAIL "</table><br><br>\n";
-    print MAIL "Detailed backup logs:<br>\n";
-    print MAIL "<br>\n";
-    print MAIL "<pre>\n";
-    print MAIL escape_html($cmdline) . "\n";
-    print MAIL "\n";
+    $html .= "</table><br><br>\n";
+    $html .= "Detailed backup logs:<br /><br />\n";
+    $html .= "<pre>\n";
+    $html .= escape_html($cmdline) . "\n\n";
 
     foreach my $task (@$tasklist) {
        my $vmid = $task->{vmid};
        my $log = $task->{tmplog};
        if (!$log) {
-           print MAIL "$vmid: no log available\n\n";
+           $html .= "$vmid: no log available\n\n";
            next;
        }
        open (TMP, "$log");
        while (my $line = <TMP>) {
            if ($line =~ m/^\S+\s\d+\s+\d+:\d+:\d+\s+(ERROR|WARN):/) {
-               print MAIL encode8bit ("$vmid: <font color=red>". 
-                                      escape_html ($line) . "</font>"); 
+               $html .= encode8bit ("$vmid: <font color=red>".
+                                      escape_html ($line) . "</font>");
            } else {
-               print MAIL encode8bit ("$vmid: " . escape_html ($line)); 
+               $html .= encode8bit ("$vmid: " . escape_html ($line));
            }
        }
        close (TMP);
-       print MAIL "\n";
+       $html .= "\n";
     }
-    print MAIL "</pre>\n";
+    $html .= "</pre></body></html>\n";
+    # end html part
 
-    print MAIL "</body></html>\n";
+    my $subject = "vzdump backup status ($hostname) : $stat";
 
-    # end html part
-    print MAIL "\n--$boundary--\n";
+    my $dcconf = PVE::Cluster::cfs_read_file('datacenter.cfg');
+    my $mailfrom = $dcconf->{email_from} || "root";
 
-    close(MAIL);
+    PVE::Tools::sendmail($mailto, $subject, $text, $html, $mailfrom, "vzdump backup tool");
 };
 
 sub new {
@@ -593,7 +547,7 @@ sub new {
        push @$findexcl, '/var/log/?*',
                         '/tmp/?*',
                         '/var/tmp/?*',
-                        '/var/run/?*';
+                        '/var/run/?*.pid';
     }
 
     foreach my $p (@plugins) {
@@ -1240,6 +1194,10 @@ sub verify_vzdump_parameters {
 
     $param->{all} = 1 if defined($param->{exclude});
 
+    warn "option 'size' is deprecated and will be removed in a future " .
+        "release, please update your script/configuration!\n"
+       if defined($param->{size});
+
     return if !$check_missing;
 
     raise_param_exc({ vmid => "property is missing"})