[pve-devel] [PATCH v7 container 2/2] vzdump: move include logic for mountpoints to method

Aaron Lauterer a.lauterer at proxmox.com
Mon Jun 22 16:34:38 CEST 2020


Move the logic which mountpoints 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 at proxmox.com>
---
v6 -> v7:
* change key `data` to `volume_config` in return hash from
  get_backup_volumes()

v5 -> v6: create hash with volume data directly in push call instead of
adding a new variable beforehand

v4->v5:
* use new `foreach_volume`
* change $ret_volumes to $return_volumes
* in PVE::VZDump::LXC change variables to better names and and use
  dedicated variables instead of hash when used more than once


 src/PVE/LXC/Config.pm | 24 ++++++++++++++++++++++++
 src/PVE/VZDump/LXC.pm | 37 ++++++++++++++++++++++---------------
 2 files changed, 46 insertions(+), 15 deletions(-)

diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index 9fab175..9839124 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -1549,4 +1549,28 @@ sub get_replicatable_volumes {
     return $volhash;
 }
 
+sub get_backup_volumes {
+    my ($class, $conf) = @_;
+
+    my $return_volumes = [];
+
+    my $test_mountpoint = sub {
+	my ($key, $volume) = @_;
+
+	my ($included, $reason) = $class->mountpoint_backup_enabled($key, $volume);
+
+
+	push @$return_volumes, {
+	    key => $key,
+	    included => $included,
+	    reason => $reason,
+	    volume_config => $volume,
+	};
+    };
+
+    PVE::LXC::Config->foreach_volume($conf, $test_mountpoint);
+
+    return $return_volumes;
+}
+
 1;
diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm
index ca3dc10..57af189 100644
--- a/src/PVE/VZDump/LXC.pm
+++ b/src/PVE/VZDump/LXC.pm
@@ -118,30 +118,37 @@ sub prepare {
     $task->{rootgid} = $rootgid;
 
     my $volids = $task->{volids} = [];
-    PVE::LXC::Config->foreach_volume($conf, sub {
-	my ($name, $data) = @_;
-	my $volid = $data->{volume};
-	my $mount = $data->{mp};
-	my $type = $data->{type};
 
-	return if !$volid || !$mount;
+    my $backup_volumes = PVE::LXC::Config->get_backup_volumes($conf);
 
-	if (!PVE::LXC::Config->mountpoint_backup_enabled($name, $data)) {
+    foreach my $current_volume (@{$backup_volumes}) {
+	my $name = $current_volume->{key};
+	my $included = $current_volume->{included};
+	my $volume_config = $current_volume->{volume_config};
+
+	my $volume = $volume_config->{volume};
+	my $mount = $volume_config->{mp};
+	my $type = $volume_config->{type};
+
+	next if !$volume || !$mount;
+
+	if (!$included) {
 	    push @$exclude_dirs, $mount;
 	    $self->loginfo("excluding $type mount point $name ('$mount') from backup");
-	    return;
+	    next;
 	}
 
-	$data->{name} = $name;
+	$volume_config->{name} = $name;
 
 	# immutable raw base images need RO mount
-	if ($conf->{template} && !defined($data->{ro})) {
-	    $data->{ro} = 1;
+	if ($conf->{template} && !defined($volume_config->{ro})) {
+	    $volume_config->{ro} = 1;
 	}
-	push @$disks, $data;
-	push @$volids, $volid
-	    if $type eq 'volume';
-    });
+
+	$self->loginfo("including mount point $name ('$mount') in backup");
+	push @$disks, $volume_config;
+	push @$volids, $volume if $included;
+    }
 
     if ($mode eq 'snapshot') {
 	if (!PVE::LXC::Config->has_feature('snapshot', $conf, $storage_cfg, undef, undef, 1)) {
-- 
2.20.1





More information about the pve-devel mailing list