From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v5 3/5] tape/inventory: add completion helper for tape snapshots
Date: Tue, 11 May 2021 12:50:05 +0200 [thread overview]
Message-ID: <20210511105007.3980-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210511105007.3980-1-d.csapak@proxmox.com>
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/tape/inventory.rs | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/src/tape/inventory.rs b/src/tape/inventory.rs
index f9654538..4bb6d4f8 100644
--- a/src/tape/inventory.rs
+++ b/src/tape/inventory.rs
@@ -54,6 +54,7 @@ use crate::{
tape::{
TAPE_STATUS_DIR,
MediaSet,
+ MediaCatalog,
file_formats::{
MediaLabel,
MediaSetLabel,
@@ -850,3 +851,38 @@ pub fn complete_media_label_text(
inventory.map.values().map(|entry| entry.id.label.label_text.clone()).collect()
}
+
+pub fn complete_media_set_snapshots(_arg: &str, param: &HashMap<String, String>) -> Vec<String> {
+ let media_set_uuid: Uuid = match param.get("media-set").and_then(|s| s.parse().ok()) {
+ Some(uuid) => uuid,
+ None => return Vec::new(),
+ };
+ let status_path = Path::new(TAPE_STATUS_DIR);
+ let inventory = match Inventory::load(&status_path) {
+ Ok(inventory) => inventory,
+ Err(_) => return Vec::new(),
+ };
+
+ let mut res = Vec::new();
+ let media_ids = inventory.list_used_media().into_iter().filter(|media| {
+ match &media.media_set_label {
+ Some(label) => label.uuid == media_set_uuid,
+ None => false,
+ }
+ });
+
+ for media_id in media_ids {
+ let catalog = match MediaCatalog::open(status_path, &media_id, false, false) {
+ Ok(catalog) => catalog,
+ Err(_) => continue,
+ };
+
+ for (store, content) in catalog.content() {
+ for snapshot in content.snapshot_index.keys() {
+ res.push(format!("{}:{}", store, snapshot));
+ }
+ }
+ }
+
+ res
+}
--
2.20.1
next prev parent reply other threads:[~2021-05-11 10:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-11 10:50 [pbs-devel] [PATCH proxmox-backup v5 0/5] tape: single snapshot restore Dominik Csapak
2021-05-11 10:50 ` [pbs-devel] [PATCH proxmox-backup v5 1/5] api2/tape/restore: refactor restore code into its own function Dominik Csapak
2021-05-11 10:50 ` [pbs-devel] [PATCH proxmox-backup v5 2/5] api2/tape/restore: add optional snapshots to 'restore' Dominik Csapak
2021-05-11 10:50 ` Dominik Csapak [this message]
2021-05-11 10:50 ` [pbs-devel] [PATCH proxmox-backup v5 4/5] bin/proxmox-tape: add optional snapshots to restore command Dominik Csapak
2021-05-11 10:50 ` [pbs-devel] [PATCH proxmox-backup v5 5/5] ui: tape: add single snapshot restore Dominik Csapak
2021-05-11 11:11 ` [pbs-devel] applied: [PATCH proxmox-backup v5 0/5] tape: " 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=20210511105007.3980-4-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