mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-10-04 21:14:21 +00:00
vzdump: move include logic for volumes to method
Move the logic which volumes are included in the backup job to its own method and adapt the VZDump code accordingly. This makes it possible to develop other features around backup jobs. Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
This commit is contained in:
parent
a4e128a9a9
commit
185df962a5
@ -165,6 +165,38 @@ sub get_replicatable_volumes {
|
|||||||
return $volhash;
|
return $volhash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_backup_volumes {
|
||||||
|
my ($class, $conf) = @_;
|
||||||
|
|
||||||
|
my $return_volumes = [];
|
||||||
|
|
||||||
|
my $test_volume = sub {
|
||||||
|
my ($key, $drive) = @_;
|
||||||
|
|
||||||
|
return if PVE::QemuServer::drive_is_cdrom($drive);
|
||||||
|
|
||||||
|
my $included = $drive->{backup} // 1;
|
||||||
|
my $reason = "backup=";
|
||||||
|
$reason .= defined($drive->{backup}) ? 'no' : 'yes';
|
||||||
|
|
||||||
|
if ($key =~ m/^efidisk/ && (!defined($conf->{bios}) || $conf->{bios} ne 'ovmf')) {
|
||||||
|
$included = 0;
|
||||||
|
$reason = "efidisk but no OMVF BIOS";
|
||||||
|
}
|
||||||
|
|
||||||
|
push @$return_volumes, {
|
||||||
|
key => $key,
|
||||||
|
included => $included,
|
||||||
|
reason => $reason,
|
||||||
|
volume_config => $drive,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
PVE::QemuConfig->foreach_volume($conf, $test_volume);
|
||||||
|
|
||||||
|
return $return_volumes;
|
||||||
|
}
|
||||||
|
|
||||||
sub __snapshot_save_vmstate {
|
sub __snapshot_save_vmstate {
|
||||||
my ($class, $vmid, $conf, $snapname, $storecfg, $statestorage, $suspend) = @_;
|
my ($class, $vmid, $conf, $snapname, $storecfg, $statestorage, $suspend) = @_;
|
||||||
|
|
||||||
|
@ -69,28 +69,25 @@ sub prepare {
|
|||||||
|
|
||||||
my $vollist = [];
|
my $vollist = [];
|
||||||
my $drivehash = {};
|
my $drivehash = {};
|
||||||
PVE::QemuConfig->foreach_volume($conf, sub {
|
my $backup_volumes = PVE::QemuConfig->get_backup_volumes($conf);
|
||||||
my ($ds, $drive) = @_;
|
|
||||||
|
|
||||||
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 (!$volume->{included}) {
|
||||||
|
$self->loginfo("exclude disk '$name' '$volid' ($volume->{reason})");
|
||||||
if (defined($drive->{backup}) && !$drive->{backup}) {
|
next;
|
||||||
$self->loginfo("exclude disk '$ds' '$volid' (backup=no)");
|
} elsif ($self->{vm_was_running} && $volume_config->{iothread}) {
|
||||||
return;
|
|
||||||
} elsif ($self->{vm_was_running} && $drive->{iothread}) {
|
|
||||||
if (!PVE::QemuServer::Machine::runs_at_least_qemu_version($vmid, 4, 0, 1)) {
|
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";
|
"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 {
|
} else {
|
||||||
my $log = "include disk '$ds' '$volid'";
|
my $log = "include disk '$name' '$volid'";
|
||||||
if (defined $drive->{size}) {
|
if (defined(my $size = $volume_config->{size})) {
|
||||||
my $readable_size = PVE::JSONSchema::format_size($drive->{size});
|
my $readable_size = PVE::JSONSchema::format_size($size);
|
||||||
$log .= " $readable_size";
|
$log .= " $readable_size";
|
||||||
}
|
}
|
||||||
$self->loginfo($log);
|
$self->loginfo($log);
|
||||||
@ -98,8 +95,8 @@ sub prepare {
|
|||||||
|
|
||||||
my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
|
my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
|
||||||
push @$vollist, $volid if $storeid;
|
push @$vollist, $volid if $storeid;
|
||||||
$drivehash->{$ds} = $drive;
|
$drivehash->{$name} = $volume->{volume_config};
|
||||||
});
|
}
|
||||||
|
|
||||||
PVE::Storage::activate_volumes($self->{storecfg}, $vollist);
|
PVE::Storage::activate_volumes($self->{storecfg}, $vollist);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user