Adds an optional parameter which allows to specify the names of
mountpoints which should be excluded from restore.

These mountpoints are not (re-)created and files located below the
mountpoint are not restored from backup.

Signed-off-by: Christian Ebner <c.eb...@proxmox.com>
---

changes since v1:
    not present in v1

 src/PVE/API2/LXC.pm   | 14 ++++++++++++--
 src/PVE/LXC/Create.pm | 11 +++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 090dddf..523afb8 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -162,6 +162,12 @@ __PACKAGE__->register_method({
                type => 'boolean',
                description => "Mark this as restore task.",
            },
+           'exclude-mps' => {
+               optional => 1,
+               type => 'string',
+               description => "Comma separated lists of mountpoint to exclude 
from restore.",
+               pattern => '(mp\d+)(,mp\d+)*',
+           },
            unique => {
                optional => 1,
                type => 'boolean',
@@ -222,6 +228,8 @@ __PACKAGE__->register_method({
        # 'unprivileged' is read-only, so we can't pass it to update_pct_config
        my $unprivileged = extract_param($param, 'unprivileged');
        my $restore = extract_param($param, 'restore');
+       my $exclude_mps = extract_param($param, 'exclude-mps');
+       my %excludes = map {$_ => 1} split(',', $exclude_mps) if $exclude_mps;
        my $unique = extract_param($param, 'unique');
 
        $param->{cpuunits} = PVE::CGroup::clamp_cpu_shares($param->{cpuunits})
@@ -427,8 +435,9 @@ __PACKAGE__->register_method({
                            if !defined($mp_param->{rootfs});
                        PVE::LXC::Config->foreach_volume($mp_param, sub {
                            my ($ms, $mountpoint) = @_;
-                           if ($ms eq 'rootfs' || $mountpoint->{backup}) {
-                               # backup conf contains the mp, clear for retsore
+                           if ($ms eq 'rootfs' || ($mountpoint->{backup} && 
!$excludes{$ms})) {
+                               # backup conf contains the mp and it is not in 
exclude list,
+                               # clear for retsore
                                $clear_mps->{$ms} = $mountpoint;
                            } else {
                                # do not add as mp, will be attach as unused at 
the end
@@ -485,6 +494,7 @@ __PACKAGE__->register_method({
 
                    my $restore_opts = {
                        'orig_mps' => $orig_mp_param,
+                       'excludes' => \%excludes,
                    };
                    PVE::LXC::Create::restore_archive(
                        $storage_cfg, $archive, $rootdir, $conf, 
$ignore_unpack_errors, $bwlimit, $restore_opts);
diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm
index 98ab4a4..34929d5 100644
--- a/src/PVE/LXC/Create.pm
+++ b/src/PVE/LXC/Create.pm
@@ -129,6 +129,11 @@ sub restore_proxmox_backup_archive {
            return;
        }
 
+       if (defined($restore_opts->{excludes}->{$name})) {
+           print "'$name': mp excluded from restore.\n";
+           return;
+       }
+
        if ($name ne 'rootfs' && (!defined($orig_mp->{backup}) || 
!$orig_mp->{backup})) {
            print "'$name': mp not included in original backup.\n";
            return;
@@ -221,6 +226,12 @@ sub restore_tar_archive {
     push @$cmd, '--skip-old-files';
     push @$cmd, '--anchored';
     push @$cmd, '--exclude' , './dev/*';
+    
+    my $orig_mps = $restore_opts->{orig_mps};
+    my $excludes = $restore_opts->{excludes};
+    foreach my $name (keys %$excludes) {
+       push @$cmd, '--exclude', ".$orig_mps->{$name}->{mp}" if 
defined($orig_mps->{$name}->{mp});
+    }
 
     if (defined($bwlimit)) {
        $cmd = [ ['cstream', '-t', $bwlimit*1024], $cmd ];
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to