From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id EFAAF6A17B for ; Wed, 9 Dec 2020 09:43:41 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DE66DDB91 for ; Wed, 9 Dec 2020 09:43:11 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 9E589DB86 for ; Wed, 9 Dec 2020 09:43:09 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 66E07442C6 for ; Wed, 9 Dec 2020 09:43:09 +0100 (CET) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Wed, 9 Dec 2020 09:42:57 +0100 Message-Id: <20201209084257.72850-1-h.laimer@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [inspect.rs, proxmox-backup-manager.rs, mod.rs] Subject: [pbs-devel] [PATCH proxmox-backup] add inspection in proxmox-backup-manager for .blob, .didx and .fidx files X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Dec 2020 08:43:42 -0000 Signed-off-by: Hannes Laimer --- Add print_info function for DynamicIndex and inspection of .blob, .didx and .fidx files to proxmox-backup-manager src/api2/types/mod.rs | 2 + src/backup/dynamic_index.rs | 14 ++++ src/bin/proxmox-backup-manager.rs | 1 + src/bin/proxmox_backup_manager/inspect.rs | 80 +++++++++++++++++++++++ src/bin/proxmox_backup_manager/mod.rs | 2 + 5 files changed, 99 insertions(+) create mode 100644 src/bin/proxmox_backup_manager/inspect.rs diff --git a/src/api2/types/mod.rs b/src/api2/types/mod.rs index 59b2433f..fe89dc78 100644 --- a/src/api2/types/mod.rs +++ b/src/api2/types/mod.rs @@ -253,6 +253,8 @@ pub const TIME_ZONE_SCHEMA: Schema = StringSchema::new( .max_length(64) .schema(); +pub const FILE_SCHEMA: Schema = StringSchema::new("File").schema(); + pub const ACL_PATH_SCHEMA: Schema = StringSchema::new( "Access control path.") .format(&ACL_PATH_FORMAT) diff --git a/src/backup/dynamic_index.rs b/src/backup/dynamic_index.rs index df651906..35dde880 100644 --- a/src/backup/dynamic_index.rs +++ b/src/backup/dynamic_index.rs @@ -183,6 +183,20 @@ impl DynamicIndexReader { self.binary_search(middle_idx + 1, middle_end, end_idx, end, offset) } } + + pub fn print_info(&self) { + println!("Size: {}", self.size); + + let mut ctime_str = self.ctime.to_string(); + if let Ok(s) = proxmox::tools::time::strftime_local("%c", self.ctime) { + ctime_str = s; + } + + println!("Index entries: {}", self.index.len()); + + println!("CTime: {}", ctime_str); + println!("UUID: {:?}", self.uuid); + } } impl IndexFile for DynamicIndexReader { diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs index a763d6d6..3e023965 100644 --- a/src/bin/proxmox-backup-manager.rs +++ b/src/bin/proxmox-backup-manager.rs @@ -409,6 +409,7 @@ fn main() { .insert("datastore", datastore_commands()) .insert("disk", disk_commands()) .insert("dns", dns_commands()) + .insert("inspect", inspect_commands()) .insert("network", network_commands()) .insert("user", user_commands()) .insert("remote", remote_commands()) diff --git a/src/bin/proxmox_backup_manager/inspect.rs b/src/bin/proxmox_backup_manager/inspect.rs new file mode 100644 index 00000000..8dd834c3 --- /dev/null +++ b/src/bin/proxmox_backup_manager/inspect.rs @@ -0,0 +1,80 @@ +use std::fs::File; +use std::io::Read; +use std::path::Path; + +use anyhow::Error; +use proxmox::api::{api, cli::*, RpcEnvironment}; +use serde_json::Value; + +use proxmox_backup::tools; +use proxmox_backup::api2::types::*; +use proxmox_backup::backup::{DataBlob, DynamicIndexReader, FixedIndexReader}; + +#[api( + input: { + properties: { + file: { + schema: FILE_SCHEMA, + } + } + } +)] +/// Inspect a .blob file +fn inspect_blob(param: Value, _rpcenv: &mut dyn RpcEnvironment) -> Result { + let path = tools::required_string_param(¶m, "file")?; + + let mut file = File::open(path)?; + let mut buffer = Vec::new(); + file.read_to_end(&mut buffer)?; + let data_blob = DataBlob::load_from_reader(&mut &buffer[..])?; + + println!("{}", String::from_utf8(data_blob.decode(None, None)?)?); + + Ok(Value::Null) +} + +#[api( + input: { + properties: { + file: { + schema: FILE_SCHEMA, + } + } + } +)] +/// Inspect a .fidx file +fn inspect_fixed_index(param: Value, _rpcenv: &mut dyn RpcEnvironment) -> Result { + let path = tools::required_string_param(¶m, "file")?; + + let index = FixedIndexReader::open(Path::new(path))?; + index.print_info(); + Ok(Value::Null) +} + +#[api( + input: { + properties: { + file: { + schema: FILE_SCHEMA, + } + } + } +)] +/// Inspect a .didx file +fn inspect_dynamic_index(param: Value, _rpcenv: &mut dyn RpcEnvironment) -> Result { + let path = tools::required_string_param(¶m, "file")?; + + let index = DynamicIndexReader::open(Path::new(path))?; + index.print_info(); + Ok(Value::Null) +} + +pub fn inspect_commands() -> CommandLineInterface { + + let cmd_def = CliCommandMap::new() + .insert("blob",CliCommand::new(&API_METHOD_INSPECT_BLOB)) + .insert("fidx",CliCommand::new(&API_METHOD_INSPECT_FIXED_INDEX)) + .insert("didx",CliCommand::new(&API_METHOD_INSPECT_DYNAMIC_INDEX)); + + cmd_def.into() +} diff --git a/src/bin/proxmox_backup_manager/mod.rs b/src/bin/proxmox_backup_manager/mod.rs index 1f3ff92e..7b2854d7 100644 --- a/src/bin/proxmox_backup_manager/mod.rs +++ b/src/bin/proxmox_backup_manager/mod.rs @@ -6,6 +6,8 @@ mod datastore; pub use datastore::*; mod dns; pub use dns::*; +mod inspect; +pub use inspect::*; mod network; pub use network::*; mod remote; -- 2.20.1