]> git.proxmox.com Git - pve-manager.git/blobdiff - PVE/API2/VZDump.pm
VZDump: mark 'size' as deprecated, warn if set
[pve-manager.git] / PVE / API2 / VZDump.pm
index 6ce9f40247fab5f0fba0dc84369d152079783149..712c7129915e5f2219166af4cd7204ee325a98a2 100644 (file)
@@ -22,6 +22,10 @@ __PACKAGE__->register_method ({
     path => '',
     method => 'POST',
     description => "Create backup.",
+    permissions => {
+       description => "The user needs 'VM.Backup' permissions on any VM, and 'Datastore.AllocateSpace' on the backup storage.",
+       user => 'all',
+    },
     protected => 1,
     proxyto => 'node',
     parameters => {
@@ -58,13 +62,18 @@ __PACKAGE__->register_method ({
        PVE::VZDump::verify_vzdump_parameters($param, 1);
 
        # silent exit if we run on wrong node
-       exit(0) if $param->{node} && $param->{node} ne $nodename;
-
+       return 'OK' if $param->{node} && $param->{node} ne $nodename;
+       
        my $cmdline = PVE::VZDump::command_line($param);
 
        # convert string lists to arrays
        my @vmids = PVE::Tools::split_list(extract_param($param, 'vmid'));
 
+       if($param->{stop}){
+           PVE::VZDump::stop_running_backups();
+           return 'OK' if !scalar(@vmids);
+       }
+
        my $skiplist = [];
        if (!$param->{all}) {
            if (!$param->{node}) {
@@ -80,7 +89,7 @@ __PACKAGE__->register_method ({
                }
                @vmids = @localvmids;
                # silent exit if specified VMs run on other nodes
-               exit(0) if !scalar(@vmids);
+               return "OK" if !scalar(@vmids);
            }
 
            $param->{vmids} = PVE::VZDump::check_vmids(@vmids)
@@ -88,25 +97,45 @@ __PACKAGE__->register_method ({
 
        my @exclude = PVE::Tools::split_list(extract_param($param, 'exclude'));
        $param->{exclude} = PVE::VZDump::check_vmids(@exclude);
-       
+
        # exclude-path list need to be 0 separated
-       my @expaths = split(/\0/, $param->{'exclude-path'} || '');
-       $param->{'exclude-path'} = [ @expaths ];
+       if (defined($param->{'exclude-path'})) {
+           my @expaths = split(/\0/, $param->{'exclude-path'} || '');
+           $param->{'exclude-path'} = [ @expaths ];
+       }
 
-       my @mailto = PVE::Tools::split_list(extract_param($param, 'mailto'));
-       $param->{mailto} = [ @mailto ];
+       if (defined($param->{mailto})) {
+           my @mailto = PVE::Tools::split_list(extract_param($param, 'mailto'));
+           $param->{mailto} = [ @mailto ];
+       }
 
        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};
+
        my $vzdump = PVE::VZDump->new($cmdline, $param, $skiplist);
 
        my $worker = sub {
+           my $upid = shift;
+
            $SIG{INT} = $SIG{TERM} = $SIG{QUIT} = $SIG{HUP} = $SIG{PIPE} = sub {
                die "interrupted by signal\n";
            };
 
-           $vzdump->getlock (); # only one process allowed
+           eval {
+               $vzdump->getlock($upid); # only one process allowed
+           };
+           if (my $err = $@) {
+               $vzdump->sendmail([], 0, $err);
+               exit(-1);
+           }
 
            if (defined($param->{ionice})) {
                if ($param->{ionice} > 7) {
@@ -115,7 +144,7 @@ __PACKAGE__->register_method ({
                    PVE::VZDump::run_command(undef, "ionice -c2 -n$param->{ionice} -p $$");
                }
            }
-           $vzdump->exec_backup(); 
+           $vzdump->exec_backup($rpcenv, $user); 
        }; 
 
        open STDOUT, '>/dev/null' if $param->{quiet} && !$param->{stdout};