From: Christian Ebner <c.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC v2 pve-container pve-manager 2/3] api: allow to exclude mountpoins from restore
Date: Mon, 23 Oct 2023 13:18:34 +0200 [thread overview]
Message-ID: <20231023111835.238407-3-c.ebner@proxmox.com> (raw)
In-Reply-To: <20231023111835.238407-1-c.ebner@proxmox.com>
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.ebner@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
next prev parent reply other threads:[~2023-10-23 11:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-23 11:18 [pve-devel] [RFC v2 pve-container pve-manager 0/3] add partial restore Christian Ebner
2023-10-23 11:18 ` [pve-devel] [RFC v2 pve-container pve-manager 1/3] backup: do not delete not backed-up mps on restore Christian Ebner
2023-10-23 11:18 ` Christian Ebner [this message]
2023-10-23 11:18 ` [pve-devel] [RFC v2 pve-container pve-manager 3/3] ui: lxc restore: add selective mountpoint restore Christian Ebner
2023-10-23 12:47 ` [pve-devel] [RFC v2 pve-container pve-manager 0/3] add partial restore Fiona Ebner
2023-10-23 13:03 ` Christian Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231023111835.238407-3-c.ebner@proxmox.com \
--to=c.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox