add chunk inspection to pb-debug

Adds possibility to inspect chunks and find indexes that reference the
chunk. Options:
 - chunk: path to the chunk file
 - [opt] decode: path to a file or to stdout(-), if specified, the
   chunk will be decoded into the specified location
 - [opt] digest: needed when searching for references, if set, it will
   be used for verification when decoding
 - [opt] keyfile: path to a keyfile, needed if decode is specified and
   the data was encrypted
 - [opt] reference-filter: path in which indexes that reference the
   chunk should be searched, can be a group, snapshot or the whole
   datastore, if not specified no references will be searched
 - [default=true] use-filename-as-digest: use chunk-filename as digest,
   if no digest is specified

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Hannes Laimer
2021-08-30 10:53:37 +02:00
committed by Wolfgang Bumiller
parent 86582454e8
commit 7c72ae04f1
5 changed files with 243 additions and 1 deletions

View File

@ -2,7 +2,10 @@
//!
//! This is a collection of small and useful tools.
use std::any::Any;
use std::fs::File;
use std::io::{stdout, Write};
use std::os::unix::io::RawFd;
use std::path::Path;
use anyhow::{bail, format_err, Error};
use openssl::hash::{hash, DigestBytes, MessageDigest};
@ -224,3 +227,13 @@ pub fn create_run_dir() -> Result<(), Error> {
let _: bool = create_path(pbs_buildcfg::PROXMOX_BACKUP_RUN_DIR_M!(), None, Some(opts))?;
Ok(())
}
/// Returns either a new file, if a path is given, or stdout, if no path is given.
pub fn outfile_or_stdout<P: AsRef<Path>>(path: Option<P>) -> Result<Box<dyn Write>, Error> {
if let Some(path) = path {
let f = File::create(path)?;
Ok(Box::new(f) as Box<dyn Write>)
} else {
Ok(Box::new(stdout()) as Box<dyn Write>)
}
}