]> git.proxmox.com Git - pve-manager.git/blobdiff - PVE/API2/VZDump.pm
Fix #1015: vzdump: send email on early errors
[pve-manager.git] / PVE / API2 / VZDump.pm
index 3ae98de71b2d8b2f85ced5a58efae047684bca07..2e9007856cfa0dc4a41912828c1dd86425971b2b 100644 (file)
@@ -62,17 +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;
        
-       if($param->{stop}){
-           PVE::VZDump::stop_all_backups;
-       }
-
        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}) {
@@ -88,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)
@@ -111,7 +112,7 @@ __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 size bwlimit ionice)) {
+       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');        
        }
@@ -119,18 +120,20 @@ __PACKAGE__->register_method ({
        $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";
            };
 
+           my $vzdump = PVE::VZDump->new($cmdline, $param, $skiplist);
+
            eval {
-               $vzdump->getlock(); # only one process allowed
+               $vzdump->getlock($upid); # only one process allowed
            };
-           if ($@) {
-               $vzdump->sendmail([], 0, $@);
+           if (my $err = $@) {
+               $vzdump->sendmail([], 0, $err);
                exit(-1);
            }
 
@@ -162,3 +165,42 @@ __PACKAGE__->register_method ({
 
        return $rpcenv->fork_worker('vzdump', undef, $user, $worker);
    }});
+
+__PACKAGE__->register_method ({
+    name => 'extractconfig',
+    path => 'extractconfig',
+    method => 'GET',
+    description => "Extract configuration from vzdump backup archive.",
+    permissions => {
+       description => "The user needs 'VM.Backup' permissions on the backed up guest ID, and 'Datastore.AllocateSpace' on the backup storage.",
+       user => 'all',
+    },
+    protected => 1,
+    proxyto => 'node',
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+           volume => {
+               description => "Volume identifier",
+               type => 'string',
+               completion => \&PVE::Storage::complete_volume,
+           },
+       },
+    },
+    returns => { type => 'string' },
+    code => sub {
+       my ($param) = @_;
+
+       my $volume = extract_param($param, 'volume');
+
+       my $rpcenv = PVE::RPCEnvironment::get();
+       my $authuser = $rpcenv->get_user();
+
+       my $storage_cfg = PVE::Storage::config();
+       $rpcenv->check_volume_access($authuser, $storage_cfg, undef, $volume);
+
+       return PVE::Storage::extract_vzdump_config($storage_cfg, $volume);
+    }});
+
+1;