]> git.proxmox.com Git - pve-manager.git/blobdiff - PVE/VZDump.pm
fix bug 45: skip external VMs
[pve-manager.git] / PVE / VZDump.pm
index b30146672db102f48d91654739990dc8cf7bda21..5ae091e4740137d951018450ccfdaddd225d4f1d 100644 (file)
@@ -3,6 +3,7 @@ package PVE::VZDump;
 use strict;
 use warnings;
 use Fcntl ':flock';
+use PVE::Exception qw(raise_param_exc);
 use PVE::SafeSyslog;
 use IO::File;
 use IO::Select;
@@ -211,6 +212,8 @@ sub read_vzdump_defaults {
            $res->{size} = int($1);
        } elsif ($line =~ m/maxfiles:\s*(\d+)\s*$/) {
            $res->{maxfiles} = int($1);
+       } elsif ($line =~ m/exclude-path:\s*(.*)\s*$/) {
+           $res->{'exclude-path'} = PVE::Tools::split_args($1); 
        } elsif ($line =~ m/mode:\s*(stop|snapshot|suspend)\s*$/) {
            $res->{mode} = $1;
        } else {
@@ -413,7 +416,7 @@ my $sendmail = sub {
 };
 
 sub new {
-    my ($class, $cmdline, $opts) = @_;
+    my ($class, $cmdline, $opts, $skiplist) = @_;
 
     mkpath $logdir;
 
@@ -447,13 +450,20 @@ sub new {
     $opts->{dumpdir} =~ s|/+$|| if ($opts->{dumpdir});
     $opts->{tmpdir} =~ s|/+$|| if ($opts->{tmpdir});
 
-    my $self = bless { cmdline => $cmdline, opts => $opts };
+    $skiplist = [] if !$skiplist;
+    my $self = bless { cmdline => $cmdline, opts => $opts, skiplist => $skiplist };
 
     #always skip '.'
     push @{$self->{findexcl}}, "'('", '-regex' , "'^\\.\$'", "')'", '-o';
 
     $self->find_add_exclude ('-type', 's'); # skip sockets
 
+    if ($defaults->{'exclude-path'}) {
+       foreach my $path (@{$defaults->{'exclude-path'}}) {
+           $self->find_add_exclude ('-regex', $path);
+       }
+    }
+
     if ($opts->{'exclude-path'}) {
        foreach my $path (@{$opts->{'exclude-path'}}) {
            $self->find_add_exclude ('-regex', $path);
@@ -537,7 +547,7 @@ sub get_mount_info {
 
     return undef if !$out;
    
-    my @res = split (/\s+/, $out);
+    my @res = $out =~ m/^(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)%\s+(.*)$/;
 
     return undef if scalar (@res) != 7;
 
@@ -551,7 +561,7 @@ sub get_mount_info {
 sub get_lvm_device {
     my ($dir, $mapping) = @_;
 
-    my $info = get_mount_info ($dir);
+    my $info = get_mount_info($dir);
 
     return undef if !$info;
    
@@ -681,7 +691,7 @@ sub exec_backup_task {
            $task->{tmpdir} = "$opts->{tmpdir}/vzdumptmp$$"; 
        } else {
            # dumpdir is posix? then use it as temporary dir
-           my $info = get_mount_info ($opts->{dumpdir});
+           my $info = get_mount_info($opts->{dumpdir});
            if ($vmtype eq 'qemu' || 
                grep ($_ eq $info->{fstype}, @posix_filesystems)) {
                $task->{tmpdir} = "$opts->{dumpdir}/$basename.tmp";
@@ -948,7 +958,9 @@ sub exec_backup {
     my $opts = $self->{opts};
 
     debugmsg ('info', "starting new backup job: $self->{cmdline}", undef, 1);
-
+    debugmsg ('info', "skip external VMs: " . join(', ', @{$self->{skiplist}}))
+       if scalar(@{$self->{skiplist}});
     my $tasklist = [];
 
     if ($opts->{all}) {
@@ -996,7 +1008,7 @@ sub exec_backup {
        if ($errcount) {
            debugmsg ('info', "Backup job finished with errors", undef, 1);
        } else {
-           debugmsg ('info', "Backup job finished successfuly", undef, 1);
+           debugmsg ('info', "Backup job finished successfully", undef, 1);
        }
     }
 
@@ -1140,4 +1152,47 @@ sub json_config_properties {
     return $prop;
 }
 
+sub verify_vzdump_parameters {
+    my ($param, $check_missing) = @_;
+
+    raise_param_exc({ all => "option conflicts with option 'vmid'"})
+       if $param->{all} && $param->{vmid};
+
+    raise_param_exc({ exclude => "option conflicts with option 'vmid'"})
+       if $param->{exclude} && $param->{vmid};
+
+    $param->{all} = 1 if defined($param->{exclude});
+
+    return if !$check_missing;
+
+    raise_param_exc({ vmid => "property is missing"})
+       if !$param->{all} && !$param->{vmid};
+
+}
+
+sub command_line {
+    my ($param) = @_;
+
+    my $cmd = "vzdump";
+
+    if ($param->{vmid}) {
+       $cmd .= " " . join(' ', PVE::Tools::split_list($param->{vmid}));
+    }
+
+    foreach my $p (keys %$param) {
+       next if $p eq 'id' || $p eq 'vmid' || $p eq 'starttime' || $p eq 'dow';
+       my $v = $param->{$p};
+       my $pd = $confdesc->{$p} || die "no such vzdump option '$p'\n";
+       if ($p eq 'exclude-path') {
+           foreach my $path (split(/\0/, $v || '')) {
+               $cmd .= " --$p " . PVE::Tools::shellquote($path);
+           }
+       } else {
+           $cmd .= " --$p " . PVE::Tools::shellquote($v) if defined($v) && $v ne '';
+       }
+    }
+
+    return $cmd;
+}
+
 1;