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 97AB96A18E for ; Wed, 9 Dec 2020 10:03:54 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8CFB6DD51 for ; Wed, 9 Dec 2020 10:03:54 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 96439DD43 for ; Wed, 9 Dec 2020 10:03:53 +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 5D3E644793 for ; Wed, 9 Dec 2020 10:03:53 +0100 (CET) Date: Wed, 9 Dec 2020 10:03:41 +0100 (CET) From: Dietmar Maurer To: Proxmox Backup Server development discussion , Hannes Laimer Message-ID: <1493873668.1116.1607504621900@webmail.proxmox.com> In-Reply-To: <20201209084257.72850-1-h.laimer@proxmox.com> References: <20201209084257.72850-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer v7.10.4-Rev14 X-Originating-Client: open-xchange-appsuite X-SPAM-LEVEL: Spam detection results: 0 AWL 0.114 Adjusted score from AWL reputation of From: address 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, mod.rs, proxmox.com, proxmox-backup-manager.rs] Subject: Re: [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 09:03:54 -0000 > On 12/09/2020 9:42 AM Hannes Laimer wrote: > > > 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); > + } What about referenced chunks? > } > > 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)?)?); blobs are binary data, not utf8! > + > + 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)); Can't we autodetect the file type? > + > + 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 > > > > _______________________________________________ > pbs-devel mailing list > pbs-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel