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 28B5F6BAB1 for ; Mon, 14 Dec 2020 07:54:45 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1FEAF132A2 for ; Mon, 14 Dec 2020 07:54:15 +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 7A0DE13287 for ; Mon, 14 Dec 2020 07:54:13 +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 41661450CE for ; Mon, 14 Dec 2020 07:54:13 +0100 (CET) From: Hannes Laimer To: pbs-devel@lists.proxmox.com Date: Mon, 14 Dec 2020 07:54:07 +0100 Message-Id: <20201214065407.45301-3-h.laimer@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201214065407.45301-1-h.laimer@proxmox.com> References: <20201214065407.45301-1-h.laimer@proxmox.com> 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 Subject: [pbs-devel] [PATCH proxmox-backup 2/2] add inspection of index and blob 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: Mon, 14 Dec 2020 06:54:45 -0000 Signed-off-by: Hannes Laimer --- src/bin/proxmox_backup_manager/inspect.rs | 110 ++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/src/bin/proxmox_backup_manager/inspect.rs b/src/bin/proxmox_backup_manager/inspect.rs index d9fa736e..b5587cf3 100644 --- a/src/bin/proxmox_backup_manager/inspect.rs +++ b/src/bin/proxmox_backup_manager/inspect.rs @@ -193,8 +193,118 @@ fn inspect_chunk(param: Value, _rpcenv: &mut dyn RpcEnvironment) -> Result Result { + let path = tools::required_string_param(¶m, "file")?; + let output_format = get_output_format(¶m); + + let val; + if path.ends_with(".blob") { + let decode_output_param = param["decode"].as_str(); + let key_file_param = param["keyfile"].as_str(); + + let mut file = std::fs::File::open(&path)?; + let data_blob = DataBlob::load_from_reader(&mut file)?; + + let mut decode_output_path = None; + let mut key_file_path = None; + + if let Some(path) = decode_output_param { + decode_output_path = Some(Path::new(path)) + }; + + if let Some(path) = key_file_param { + key_file_path = Some(Path::new(path)) + }; + + let crypt_mode = data_blob.crypt_mode()?; + val = json!({ + "encryption": crypt_mode, + "raw_size": data_blob.raw_size(), + }); + + if decode_output_path.is_some() { + if decode_output_param.unwrap().eq("-") { + decode_blob(None, key_file_path, None, &data_blob)?; + } else { + decode_blob(decode_output_path, key_file_path, None, &data_blob)?; + } + } + } else if path.ends_with(".fidx") { + let index = FixedIndexReader::open(Path::new(path))?; + + let mut ctime_str = index.ctime.to_string(); + if let Ok(s) = proxmox::tools::time::strftime_local("%c", index.ctime) { + ctime_str = s; + } + + let mut chunk_digests = HashSet::new(); + + for pos in 0..index.index_count() { + let digest = index.index_digest(pos).unwrap(); + chunk_digests.insert(proxmox::tools::digest_to_hex(digest)); + } + + val = json!({ + "size": index.size, + "ctime": ctime_str, + "chunk-digests": chunk_digests + + }) + } else if path.ends_with("didx") { + let index = DynamicIndexReader::open(Path::new(path))?; + + let mut ctime_str = index.ctime.to_string(); + if let Ok(s) = proxmox::tools::time::strftime_local("%c", index.ctime) { + ctime_str = s; + } + + let mut chunk_digests = HashSet::new(); + + for pos in 0..index.index_count() { + let digest = index.index_digest(pos).unwrap(); + chunk_digests.insert(proxmox::tools::digest_to_hex(digest)); + } + + val = json!({ + "size": index.size, + "ctime": ctime_str, + "chunk-digests": chunk_digests + }) + } else { + val = Value::Null; + println!("Only .blob, .fidx and didx files may be inspected"); + } + + format_and_print_result(&val, &output_format); + + Ok(Value::Null) +} + pub fn inspect_commands() -> CommandLineInterface { let cmd_def = CliCommandMap::new() + .insert("file", CliCommand::new(&API_METHOD_INSPECT_FILE)) .insert("chunk", CliCommand::new(&API_METHOD_INSPECT_CHUNK)); cmd_def.into() -- 2.20.1