]> git.proxmox.com Git - pve-manager.git/blobdiff - PVE/API2/VZDump.pm
fix #1594: allow skipping VMIDs on other nodes from API
[pve-manager.git] / PVE / API2 / VZDump.pm
index 2e9007856cfa0dc4a41912828c1dd86425971b2b..d370467c8b82d34980bbc6a52963db9264554455 100644 (file)
@@ -11,6 +11,7 @@ use PVE::AccessControl;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::Storage;
 use PVE::VZDump;
+use PVE::API2Tools;
 
 use Data::Dumper; # fixme: remove
 
@@ -18,12 +19,12 @@ use Data::Dumper; # fixme: remove
 use base qw(PVE::RESTHandler);
 
 __PACKAGE__->register_method ({
-    name => 'vzdump', 
+    name => 'vzdump',
     path => '',
     method => 'POST',
     description => "Create backup.",
     permissions => {
-       description => "The user needs 'VM.Backup' permissions on any VM, and 'Datastore.AllocateSpace' on the backup storage.",
+       description => "The user needs 'VM.Backup' permissions on any VM, and 'Datastore.AllocateSpace' on the backup storage. The 'maxfiles', 'tmpdir', 'dumpdir', 'script', 'bwlimit' and 'ionice' parameters are restricted to the 'root\@pam' user.",
        user => 'all',
     },
     protected => 1,
@@ -56,18 +57,24 @@ __PACKAGE__->register_method ({
                if $param->{stdout};
        }
 
-       # by default we set --rsyncable for gzip
-       local $ENV{GZIP} = "--rsyncable" if !$ENV{GZIP};
+       foreach my $key (qw(maxfiles tmpdir dumpdir script bwlimit ionice)) {
+           raise_param_exc({ $key => "Only root may set this option."})
+               if defined($param->{$key}) && ($user ne 'root@pam');
+       }
 
        PVE::VZDump::verify_vzdump_parameters($param, 1);
 
        # silent exit if we run on wrong node
        return 'OK' if $param->{node} && $param->{node} ne $nodename;
-       
-       my $cmdline = PVE::VZDump::command_line($param);
 
+       my $cmdline = PVE::VZDump::command_line($param);
+       my @vmids;
        # convert string lists to arrays
-       my @vmids = PVE::Tools::split_list(extract_param($param, 'vmid'));
+       if ($param->{pool}) {
+           @vmids = @{PVE::API2Tools::get_resource_pool_guest_members($param->{pool})};
+       } else {
+           @vmids = PVE::Tools::split_list(extract_param($param, 'vmid'));
+       }
 
        if($param->{stop}){
            PVE::VZDump::stop_running_backups();
@@ -76,7 +83,7 @@ __PACKAGE__->register_method ({
 
        my $skiplist = [];
        if (!$param->{all}) {
-           if (!$param->{node}) {
+           if (!$param->{node} || $param->{node} eq $nodename) {
                my $vmlist = PVE::Cluster::get_vmlist();
                my @localvmids = ();
                foreach my $vmid (@vmids) {
@@ -112,11 +119,6 @@ __PACKAGE__->register_method ({
        die "you can only backup a single VM with option --stdout\n"
            if $param->{stdout} && scalar(@vmids) != 1;
 
-       foreach my $key (qw(maxfiles tmpdir dumpdir script bwlimit ionice)) {
-           raise_param_exc({ $key => "Only root may set this option."})
-               if defined($param->{$key}) && ($user ne 'root@pam');        
-       }
-
        $rpcenv->check($user, "/storage/$param->{storage}", [ 'Datastore.AllocateSpace' ])
            if $param->{storage};
 
@@ -144,8 +146,8 @@ __PACKAGE__->register_method ({
                    PVE::VZDump::run_command(undef, "ionice -c2 -n$param->{ionice} -p $$");
                }
            }
-           $vzdump->exec_backup($rpcenv, $user); 
-       }; 
+           $vzdump->exec_backup($rpcenv, $user);
+       };
 
        open STDOUT, '>/dev/null' if $param->{quiet} && !$param->{stdout};
        open STDERR, '>/dev/null' if $param->{quiet};
@@ -163,7 +165,10 @@ __PACKAGE__->register_method ({
            }
        }
 
-       return $rpcenv->fork_worker('vzdump', undef, $user, $worker);
+       my $taskid;
+       $taskid = $vmids[0] if scalar(@vmids) == 1;
+
+       return $rpcenv->fork_worker('vzdump', $taskid, $user, $worker);
    }});
 
 __PACKAGE__->register_method ({
@@ -198,7 +203,7 @@ __PACKAGE__->register_method ({
        my $authuser = $rpcenv->get_user();
 
        my $storage_cfg = PVE::Storage::config();
-       $rpcenv->check_volume_access($authuser, $storage_cfg, undef, $volume);
+       PVE::Storage::check_volume_access($rpcenv, $authuser, $storage_cfg, undef, $volume);
 
        return PVE::Storage::extract_vzdump_config($storage_cfg, $volume);
     }});