]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/VZDump/QemuServer.pm
backup: rename confusing incremental param to use-dirty-bitmap
[qemu-server.git] / PVE / VZDump / QemuServer.pm
index 46079b88c9d7241c155fa8e394fd90b33374336f..c1ae5096a52a6ab61fbbaec234d47e7e3ece2abb 100644 (file)
@@ -7,6 +7,7 @@ use File::Basename;
 use File::Path;
 use IO::File;
 use IPC::Open3;
+use JSON;
 
 use PVE::Cluster qw(cfs_read_file);
 use PVE::INotify;
@@ -69,37 +70,34 @@ sub prepare {
 
     my $vollist = [];
     my $drivehash = {};
-    PVE::QemuConfig->foreach_volume($conf, sub {
-       my ($ds, $drive) = @_;
+    my $backup_volumes = PVE::QemuConfig->get_backup_volumes($conf);
 
-       return if PVE::QemuServer::drive_is_cdrom($drive);
+    foreach my $volume (@{$backup_volumes}) {
+       my $name = $volume->{key};
+       my $volume_config = $volume->{volume_config};
+       my $volid = $volume_config->{file};
 
-       my $volid = $drive->{file};
-
-       if (defined($drive->{backup}) && !$drive->{backup}) {
-           $self->loginfo("exclude disk '$ds' '$volid' (backup=no)");
-           return;
-       } elsif ($self->{vm_was_running} && $drive->{iothread}) {
+       if (!$volume->{included}) {
+           $self->loginfo("exclude disk '$name' '$volid' ($volume->{reason})");
+           next;
+       } elsif ($self->{vm_was_running} && $volume_config->{iothread}) {
            if (!PVE::QemuServer::Machine::runs_at_least_qemu_version($vmid, 4, 0, 1)) {
-               die "disk '$ds' '$volid' (iothread=on) can't use backup feature with running QEMU " .
+               die "disk '$name' '$volid' (iothread=on) can't use backup feature with running QEMU " .
                    "version < 4.0.1! Either set backup=no for this drive or upgrade QEMU and restart VM\n";
            }
-       } elsif ($ds =~ m/^efidisk/ && (!defined($conf->{bios}) || $conf->{bios} ne 'ovmf')) {
-           $self->loginfo("excluding '$ds' (efidisks can only be backed up when BIOS is set to 'ovmf')");
-           return;
        } else {
-           my $log = "include disk '$ds' '$volid'";
-          if (defined $drive->{size}) {
-               my $readable_size = PVE::JSONSchema::format_size($drive->{size});
+           my $log = "include disk '$name' '$volid'";
+           if (defined(my $size = $volume_config->{size})) {
+               my $readable_size = PVE::JSONSchema::format_size($size);
                $log .= " $readable_size";
-          }
+           }
            $self->loginfo($log);
        }
 
        my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
        push @$vollist, $volid if $storeid;
-       $drivehash->{$ds} = $drive;
-    });
+       $drivehash->{$name} = $volume->{volume_config};
+    }
 
     PVE::Storage::activate_volumes($self->{storecfg}, $vollist);
 
@@ -210,8 +208,8 @@ sub assemble {
            } else {
                $found_snapshot = 1;
            }
-           next; # skip all snapshots and pending changes config data
        }
+       next if $found_snapshot || $found_pending; # skip all snapshots and pending changes config data
 
        if ($line =~ m/^unused\d+:\s*(\S+)\s*/) {
            $self->loginfo("skip unused drive '$1' (not included into backup)");
@@ -248,7 +246,7 @@ sub archive {
     my $opts = $self->{vzdump}->{opts};
     my $scfg = $opts->{scfg};
 
-    if ($scfg->{type} eq 'pbs') {
+    if ($self->{vzdump}->{opts}->{pbs}) {
        $self->archive_pbs($task, $vmid);
     } else {
        $self->archive_vma($task, $vmid, $filename, $comp);
@@ -298,7 +296,7 @@ my $query_backup_status_loop = sub {
                die (($status->{errmsg} || "unknown error") . "\n") if $res eq 'error';
                die "got unexpected status '$res'\n";
            } elsif ($total != $transferred) {
-               die "got wrong number of transfered bytes ($total != $transferred)\n";
+               $self->loginfo("backup was done incrementally");
            }
            last;
        }
@@ -356,6 +354,7 @@ sub archive_pbs {
        }
 
        local $ENV{PBS_PASSWORD} = $password;
+       local $ENV{PBS_FINGERPRINT} = $fingerprint if defined($fingerprint);
        my $cmd = [
            '/usr/bin/proxmox-backup-client',
            'backup',
@@ -364,7 +363,6 @@ sub archive_pbs {
            '--backup-id', "$vmid",
            '--backup-time', $task->{backup_time},
        ];
-       push @$cmd, '--fingerprint', $fingerprint if defined($fingerprint);
 
        push @$cmd, "qemu-server.conf:$conffile";
        push @$cmd, "fw.conf:$firewall" if -e $firewall;
@@ -399,10 +397,13 @@ sub archive_pbs {
            password => $password,
            devlist => $devlist,
            'config-file' => $conffile,
+           'use-dirty-bitmap' => JSON::true,
        };
        $params->{fingerprint} = $fingerprint if defined($fingerprint);
        $params->{'firewall-file'} = $firewall if -e $firewall;
 
+       $params->{timeout} = 60; # give some time to connect to the backup server
+
        my $res = eval { mon_cmd($vmid, "backup", %$params) };
        my $qmperr = $@;
        $backup_job_uuid = $res->{UUID} if $res;
@@ -518,7 +519,7 @@ sub archive_vma {
        $self->loginfo(join(' ', @$cmd));
 
        if ($opts->{stdout}) {
-           $self->cmd($cmd, output => ">&=" . fileno($opts->{stdout}));
+           $self->cmd($cmd, output => ">&" . fileno($opts->{stdout}));
        } else {
            $self->cmd($cmd);
        }