]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/VZDump/QemuServer.pm
Revert "fix #1071: VMs with IOThread enabled disks can now be backed up"
[qemu-server.git] / PVE / VZDump / QemuServer.pm
index 5322b37d2fc4ecf70a7b259dbdbb979f5da5c160..b8d8fa9b44db11a4272721b143c0a33a285c2da1 100644 (file)
@@ -12,6 +12,7 @@ use PVE::Tools;
 use PVE::Storage::Plugin;
 use PVE::Storage;
 use PVE::QemuServer;
+use PVE::JSONSchema;
 use IO::File;
 use IPC::Open3;
 
@@ -22,7 +23,7 @@ sub new {
 
     PVE::VZDump::check_bin('qm');
 
-    my $self = bless { vzdump => $vzdump };
+    my $self = bless { vzdump => $vzdump }, $class;
 
     $self->{vmlist} = PVE::QemuServer::vzlist();
     $self->{storecfg} = PVE::Storage::config();
@@ -75,7 +76,12 @@ sub prepare {
        } elsif ($drive->{iothread}) {
            die "disk '$ds' '$volid' (iothread=on) can't use backup feature currently. Please set backup=no for this drive";
        } else {
-           $self->loginfo("include disk '$ds' '$volid'");
+           my $log = "include disk '$ds' '$volid'";
+          if (defined $drive->{size}) {
+               my $readable_size = PVE::JSONSchema::format_size($drive->{size});
+               $log .= " $readable_size";
+          }
+           $self->loginfo($log);
        }
 
        my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
@@ -268,7 +274,7 @@ sub archive {
            $outcmd = "exec:cat";
        }
 
-       $outcmd .= ">$filename" if !$opts->{stdout};
+       $outcmd .= " > $filename" if !$opts->{stdout};
 
        my $cmd = ['/usr/bin/vma', 'create', '-v', '-c', $conffile];
        push @$cmd, '-c', $firewall if -e $firewall;
@@ -390,7 +396,7 @@ sub archive {
                'config-file' => $conffile,
                devlist => $devlist
            };
-           
+
            $params->{'firewall-file'} = $firewall if -e $firewall;
            $qmpclient->queue_cmd($vmid, $backup_cb, 'backup', %$params);
        };
@@ -398,21 +404,29 @@ sub archive {
        $qmpclient->queue_cmd($vmid, $add_fd_cb, 'getfd',
                              fd => $outfileno, fdname => "backup");
 
-       if ($self->{vmlist}->{$vmid}->{agent} && $vm_is_running){
+       my $agent_running = 0;
+
+       if ($self->{vmlist}->{$vmid}->{agent} && $vm_is_running) {
+           $agent_running = PVE::QemuServer::qga_check_running($vmid);
+       }
+
+       if ($agent_running){
            eval { PVE::QemuServer::vm_mon_cmd($vmid, "guest-fsfreeze-freeze"); };
            if (my $err = $@) {
                $self->logerr($err);
            }
        }
 
-       $qmpclient->queue_execute();
+       eval { $qmpclient->queue_execute() };
+       my $qmperr = $@;
 
-       if ($self->{vmlist}->{$vmid}->{agent} && $vm_is_running ){
+       if ($agent_running){
            eval { PVE::QemuServer::vm_mon_cmd($vmid, "guest-fsfreeze-thaw"); };
            if (my $err = $@) {
                $self->logerr($err);
            }
        }
+       die $qmperr if $qmperr;
        die $qmpclient->{errors}->{$vmid} if $qmpclient->{errors}->{$vmid};
 
        if ($cpid) {
@@ -425,7 +439,13 @@ sub archive {
        $self->loginfo("started backup task '$uuid'");
 
        if ($resume_on_backup) {
-           $self->loginfo("resume VM");
+           if (my $stoptime = $task->{vmstoptime}) {
+               my $delay = time() - $task->{vmstoptime};
+               $task->{vmstoptime} = undef; # avoid printing 'online after ..' twice
+               $self->loginfo("resuming VM again after $delay seconds");
+           } else {
+               $self->loginfo("resuming VM again");
+           }
            PVE::QemuServer::vm_mon_cmd($vmid, 'cont');
        }
 
@@ -462,7 +482,7 @@ sub archive {
 
            my $statusline = "status: $per% ($transferred/$total), " .
                "sparse ${zero_per}% ($zero), duration $duration, " .
-               "$mbps_read/$mbps_write MB/s";
+               "read/write $mbps_read/$mbps_write MB/s";
            my $res = $status->{status} || 'unknown';
            if ($res ne 'active') {
                $self->loginfo($statusline);