From: Christian Ebner <c.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v3 proxmox-backup 15/20] api: admin: implement endpoints to recover trashed contents
Date: Tue, 13 May 2025 15:52:42 +0200 [thread overview]
Message-ID: <20250513135247.644260-16-c.ebner@proxmox.com> (raw)
In-Reply-To: <20250513135247.644260-1-c.ebner@proxmox.com>
Implements the api endpoints to recover trashed contents contained
within backup groups or individual snapshots.
Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
src/api2/admin/datastore.rs | 143 +++++++++++++++++++++++++++++++++++-
1 file changed, 142 insertions(+), 1 deletion(-)
diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 3f68edf24..3ea5b19f1 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -51,7 +51,7 @@ use pbs_api_types::{
};
use pbs_client::pxar::{create_tar, create_zip};
use pbs_config::CachedUserInfo;
-use pbs_datastore::backup_info::BackupInfo;
+use pbs_datastore::backup_info::{BackupInfo, TRASH_MARKER_FILENAME};
use pbs_datastore::cached_chunk_reader::CachedChunkReader;
use pbs_datastore::catalog::{ArchiveEntry, CatalogReader};
use pbs_datastore::data_blob::DataBlob;
@@ -2724,6 +2724,139 @@ pub async fn unmount(store: String, rpcenv: &mut dyn RpcEnvironment) -> Result<V
Ok(json!(upid))
}
+#[api(
+ input: {
+ properties: {
+ store: { schema: DATASTORE_SCHEMA },
+ group: {
+ type: pbs_api_types::BackupGroup,
+ flatten: true,
+ },
+ ns: {
+ type: BackupNamespace,
+ optional: true,
+ },
+ },
+ },
+ access: {
+ permission: &Permission::Anybody,
+ description: "Requires on /datastore/{store}[/{namespace}] either DATASTORE_MODIFY for any \
+ or DATASTORE_BACKUP and being the owner of the group",
+ },
+)]
+/// Recover trashed contents of a backup group.
+pub fn recover_group(
+ store: String,
+ group: pbs_api_types::BackupGroup,
+ ns: Option<BackupNamespace>,
+ rpcenv: &mut dyn RpcEnvironment,
+) -> Result<(), Error> {
+ let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
+ let ns = ns.unwrap_or_default();
+ let datastore = check_privs_and_load_store(
+ &store,
+ &ns,
+ &auth_id,
+ PRIV_DATASTORE_MODIFY,
+ PRIV_DATASTORE_BACKUP,
+ Some(Operation::Write),
+ &group,
+ )?;
+
+ let backup_group = datastore.backup_group(ns, group);
+ do_recover_group(&backup_group)?;
+
+ Ok(())
+}
+
+fn do_recover_group(backup_group: &BackupGroup) -> Result<(), Error> {
+ let _exclusive_lock = backup_group
+ .lock()
+ .with_context(|| "while recovering group {backup_group:?}")?;
+ let trashed_snapshots = backup_group.list_backups(TrashStateFilter::OnlyTrash)?;
+ for snapshot in trashed_snapshots {
+ do_recover_snapshot(&snapshot.backup_dir)?;
+ }
+
+ let group_trash_path = backup_group.full_group_path().join(TRASH_MARKER_FILENAME);
+ if let Err(err) = std::fs::remove_file(&group_trash_path) {
+ if err.kind() != std::io::ErrorKind::NotFound {
+ bail!("failed to remove group trash file {group_trash_path:?} - {err}");
+ }
+ }
+ Ok(())
+}
+
+#[api(
+ input: {
+ properties: {
+ store: { schema: DATASTORE_SCHEMA },
+ backup_dir: {
+ type: pbs_api_types::BackupDir,
+ flatten: true,
+ },
+ ns: {
+ type: BackupNamespace,
+ optional: true,
+ },
+ },
+ },
+ access: {
+ permission: &Permission::Anybody,
+ description: "Requires on /datastore/{store}[/{namespace}] either DATASTORE_MODIFY for any \
+ or DATASTORE_BACKUP and being the owner of the group",
+ },
+)]
+/// Recover trashed contents of a backup snapshot.
+pub fn recover_snapshot(
+ store: String,
+ backup_dir: pbs_api_types::BackupDir,
+ ns: Option<BackupNamespace>,
+ rpcenv: &mut dyn RpcEnvironment,
+) -> Result<(), Error> {
+ let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
+ let ns = ns.unwrap_or_default();
+ let datastore = check_privs_and_load_store(
+ &store,
+ &ns,
+ &auth_id,
+ PRIV_DATASTORE_MODIFY,
+ PRIV_DATASTORE_BACKUP,
+ Some(Operation::Write),
+ &backup_dir.group,
+ )?;
+
+ let backup_group = datastore.backup_group(ns.clone(), backup_dir.group.clone());
+ let snapshot = datastore.backup_dir(ns, backup_dir)?;
+ let _exclusive_group_lock = backup_group
+ .lock()
+ .with_context(|| "while recovering snapshot {snapshot_dir:?}")?;
+
+ do_recover_snapshot(&snapshot)?;
+
+ let group_trash_path = backup_group.full_group_path().join(TRASH_MARKER_FILENAME);
+ if let Err(err) = std::fs::remove_file(&group_trash_path) {
+ if err.kind() != std::io::ErrorKind::NotFound {
+ bail!("failed to remove group trash file {group_trash_path:?} - {err}");
+ }
+ }
+
+ Ok(())
+}
+
+fn do_recover_snapshot(snapshot_dir: &BackupDir) -> Result<(), Error> {
+ let _exclusive_lock = snapshot_dir
+ .lock()
+ .with_context(|| "while recovering snapshot {snapshot_dir:?}")?;
+ let trash_path = snapshot_dir.full_path().join(TRASH_MARKER_FILENAME);
+ if let Err(err) = std::fs::remove_file(&trash_path) {
+ if err.kind() != std::io::ErrorKind::NotFound {
+ bail!("failed to remove trash file {trash_path:?} - {err}");
+ }
+ }
+ Ok(())
+}
+
#[sortable]
const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
(
@@ -2789,6 +2922,14 @@ const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
"pxar-file-download",
&Router::new().download(&API_METHOD_PXAR_FILE_DOWNLOAD),
),
+ (
+ "recover-group",
+ &Router::new().put(&API_METHOD_RECOVER_GROUP),
+ ),
+ (
+ "recover-snapshot",
+ &Router::new().put(&API_METHOD_RECOVER_SNAPSHOT),
+ ),
("rrd", &Router::new().get(&API_METHOD_GET_RRD_STATS)),
(
"snapshots",
--
2.39.5
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2025-05-13 13:52 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-13 13:52 [pbs-devel] [PATCH v3 proxmox proxmox-backup 00/20] implement trash bin functionality Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox 1/20] pbs api types: add type for snapshot list filtering based on trash state Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox 2/20] pbs api types: datastore: add trash marker to snapshot list item Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 03/20] datastore/api: mark snapshots as trash on destroy Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 04/20] datastore: mark groups " Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 05/20] datastore: add helpers to check if snapshot/group is trash Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 06/20] datastore: allow filtering of backups by their trash state Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 07/20] api: datastore: add trash state filtering for snapshot listing Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 08/20] datastore: ignore trashed snapshots for last successful backup Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 09/20] sync: ignore trashed snapshots/groups when reading from local source Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 10/20] api: tape: check trash marker when trying to write snapshot Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 11/20] datastore: clear trashed snapshot dir if re-creation requested Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 12/20] datastore: recover backup group from trash for new backups Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 13/20] datastore: garbage collection: clean-up trashed snapshots and groups Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 14/20] client: expose skip trash flags for cli commands Christian Ebner
2025-05-13 13:52 ` Christian Ebner [this message]
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 16/20] api: admin: move backup group list generation into helper Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 17/20] api: admin: add endpoint to clear trashed items from group Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 18/20] ui: add recover for trashed items tab to datastore panel Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 19/20] ui: drop 'permanent' in group/snapshot forget, default is to trash Christian Ebner
2025-05-13 13:52 ` [pbs-devel] [PATCH v3 proxmox-backup 20/20] ui: mention trash items will be cleared on namespace deletion 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=20250513135247.644260-16-c.ebner@proxmox.com \
--to=c.ebner@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.