From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 09/11] api: admin/datastore: add new 'prune-datastore' api call
Date: Fri, 16 Jul 2021 10:53:26 +0200 [thread overview]
Message-ID: <20210716085328.3731574-10-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210716085328.3731574-1-d.csapak@proxmox.com>
to prune the whole datastore at once, with the given parameters.
We need a new api call since this can take a while and we need to start
a worker for this. The exisiting api call returns a list of removed/kept
snapshots and is synchronous.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/api2/admin/datastore.rs | 63 ++++++++++++++++++++++++++++++++++++-
src/server/prune_job.rs | 9 ++++--
2 files changed, 69 insertions(+), 3 deletions(-)
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 79ab97e7..60941501 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -820,7 +820,7 @@ pub fn verify(
permission: &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_MODIFY | PRIV_DATASTORE_PRUNE, true),
},
)]
-/// Prune the datastore
+/// Prune a group on the datastore
pub fn prune(
backup_id: String,
backup_type: String,
@@ -922,6 +922,62 @@ pub fn prune(
Ok(json!(prune_result))
}
+#[api(
+ input: {
+ properties: {
+ "dry-run": {
+ optional: true,
+ type: bool,
+ default: false,
+ description: "Just show what prune would do, but do not delete anything.",
+ },
+ "prune-options": {
+ type: PruneOptions,
+ flatten: true,
+ },
+ store: {
+ schema: DATASTORE_SCHEMA,
+ },
+ },
+ },
+ returns: {
+ schema: UPID_SCHEMA,
+ },
+ access: {
+ permission: &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_MODIFY | PRIV_DATASTORE_PRUNE, true),
+ },
+)]
+/// Prune the datastore
+pub fn prune_datastore(
+ dry_run: bool,
+ prune_options: PruneOptions,
+ store: String,
+ _param: Value,
+ rpcenv: &mut dyn RpcEnvironment,
+) -> Result<String, Error> {
+
+ let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
+
+ let datastore = DataStore::lookup_datastore(&store)?;
+
+ let upid_str = WorkerTask::new_thread(
+ "prune",
+ Some(store.clone()),
+ auth_id.clone(),
+ false,
+ move |worker| crate::server::prune_datastore(
+ worker.clone(),
+ auth_id,
+ prune_options,
+ &store,
+ datastore,
+ dry_run
+ ),
+ )?;
+
+ Ok(upid_str)
+}
+
#[api(
input: {
properties: {
@@ -1844,6 +1900,11 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
&Router::new()
.post(&API_METHOD_PRUNE)
),
+ (
+ "prune-datastore",
+ &Router::new()
+ .post(&API_METHOD_PRUNE_DATASTORE)
+ ),
(
"pxar-file-download",
&Router::new()
diff --git a/src/server/prune_job.rs b/src/server/prune_job.rs
index bbf53ade..255e21ce 100644
--- a/src/server/prune_job.rs
+++ b/src/server/prune_job.rs
@@ -19,9 +19,14 @@ pub fn prune_datastore(
prune_options: PruneOptions,
store: &str,
datastore: Arc<DataStore>,
+ dry_run: bool,
) -> Result<(), Error> {
task_log!(worker, "Starting datastore prune on store \"{}\"", store);
+ if dry_run {
+ task_log!(worker, "(dry test run)");
+ }
+
let keep_all = !prune_options.keeps_something();
if keep_all {
@@ -69,7 +74,7 @@ pub fn prune_datastore(
group.backup_id(),
info.backup_dir.backup_time_string()
);
- if !keep {
+ if !keep && !dry_run {
if let Err(err) = datastore.remove_backup_dir(&info.backup_dir, false) {
task_warn!(
worker,
@@ -108,7 +113,7 @@ pub fn do_prune_job(
task_log!(worker, "task triggered by schedule '{}'", event_str);
}
- let result = prune_datastore(worker.clone(), auth_id, prune_options, &store, datastore);
+ let result = prune_datastore(worker.clone(), auth_id, prune_options, &store, datastore, false);
let status = worker.create_state(&result);
--
2.30.2
next prev parent reply other threads:[~2021-07-16 8:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-16 8:53 [pbs-devel] [PATCH proxmox-backup 00/11] add 'prune all' button to datastore content Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 01/11] api-types: move PRUNE_SCHEMA_KEEP_* to pbs-api-types Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 02/11] pbs-datastore/prune: make PruneOptions an api type Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 03/11] client: simplify prune api method Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 04/11] api: admin/datastore: simplify prune api call Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 05/11] backup/datastore: refactor check_backup_owner there Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 06/11] server/prune_job: factor out 'prune_datastore' Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 07/11] server/prune_job: add 'keep_all' logic to 'prune_datastore' Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 08/11] server/prune_job: add proper permission checks " Dominik Csapak
2021-07-16 8:53 ` Dominik Csapak [this message]
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 10/11] ui: datastore/Content: add 'Prune All' button Dominik Csapak
2021-07-16 8:53 ` [pbs-devel] [PATCH proxmox-backup 11/11] ui: datastore/Prune: improve title of group prune window Dominik Csapak
2021-07-16 9:48 ` [pbs-devel] applied: [PATCH proxmox-backup 00/11] add 'prune all' button to datastore content Dietmar Maurer
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=20210716085328.3731574-10-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pbs-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