split out proxmox-backup-debug binary
and introduce pbs_tools::cli module Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
dd2162f6bd
commit
e5f9b7f79e
@ -30,6 +30,7 @@ members = [
|
|||||||
|
|
||||||
"proxmox-backup-banner",
|
"proxmox-backup-banner",
|
||||||
"proxmox-backup-client",
|
"proxmox-backup-client",
|
||||||
|
"proxmox-backup-debug",
|
||||||
"pxar-bin",
|
"pxar-bin",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
3
Makefile
3
Makefile
@ -42,6 +42,7 @@ SUBCRATES := \
|
|||||||
pbs-tools \
|
pbs-tools \
|
||||||
proxmox-backup-banner \
|
proxmox-backup-banner \
|
||||||
proxmox-backup-client \
|
proxmox-backup-client \
|
||||||
|
proxmox-backup-debug \
|
||||||
pxar-bin
|
pxar-bin
|
||||||
|
|
||||||
ifeq ($(BUILD_MODE), release)
|
ifeq ($(BUILD_MODE), release)
|
||||||
@ -171,6 +172,8 @@ $(COMPILED_BINS) $(COMPILEDIR)/dump-catalog-shell-cli $(COMPILEDIR)/docgen: .do-
|
|||||||
--bin proxmox-backup-banner \
|
--bin proxmox-backup-banner \
|
||||||
--package proxmox-backup-client \
|
--package proxmox-backup-client \
|
||||||
--bin proxmox-backup-client \
|
--bin proxmox-backup-client \
|
||||||
|
--package proxmox-backup-debug \
|
||||||
|
--bin proxmox-backup-debug \
|
||||||
--package pxar-bin \
|
--package pxar-bin \
|
||||||
--bin pxar \
|
--bin pxar \
|
||||||
--package proxmox-backup \
|
--package proxmox-backup \
|
||||||
|
13
pbs-tools/src/cli.rs
Normal file
13
pbs-tools/src/cli.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, stdout, Write};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
/// 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>) -> io::Result<Box<dyn Write>> {
|
||||||
|
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>)
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ pub mod blocking;
|
|||||||
pub mod borrow;
|
pub mod borrow;
|
||||||
pub mod broadcast_future;
|
pub mod broadcast_future;
|
||||||
pub mod cert;
|
pub mod cert;
|
||||||
|
pub mod cli;
|
||||||
pub mod compression;
|
pub mod compression;
|
||||||
pub mod format;
|
pub mod format;
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
|
17
proxmox-backup-debug/Cargo.toml
Normal file
17
proxmox-backup-debug/Cargo.toml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "proxmox-backup-debug"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Proxmox Support Team <support@proxmox.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = "1.0"
|
||||||
|
walkdir = "2"
|
||||||
|
serde_json = "1.0"
|
||||||
|
|
||||||
|
proxmox = { version = "0.13.0", features = [ "api-macro", "cli", "router" ] }
|
||||||
|
|
||||||
|
pbs-client = { path = "../pbs-client" }
|
||||||
|
pbs-datastore = { path = "../pbs-datastore" }
|
||||||
|
pbs-runtime = { path = "../pbs-runtime" }
|
||||||
|
pbs-tools = { path = "../pbs-tools" }
|
@ -23,7 +23,7 @@ use pbs_datastore::{load_and_decrypt_key, CryptConfig, DataBlob};
|
|||||||
|
|
||||||
use pbs_client::tools::key_source::get_encryption_key_password;
|
use pbs_client::tools::key_source::get_encryption_key_password;
|
||||||
|
|
||||||
use proxmox_backup::tools::outfile_or_stdout;
|
use pbs_tools::cli::outfile_or_stdout;
|
||||||
|
|
||||||
/// Decodes a blob and writes its content either to stdout or into a file
|
/// Decodes a blob and writes its content either to stdout or into a file
|
||||||
fn decode_blob(
|
fn decode_blob(
|
13
proxmox-backup-debug/src/main.rs
Normal file
13
proxmox-backup-debug/src/main.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
use proxmox::api::cli::{run_cli_command, CliCommandMap, CliEnvironment};
|
||||||
|
|
||||||
|
mod inspect;
|
||||||
|
mod recover;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let cmd_def = CliCommandMap::new()
|
||||||
|
.insert("inspect", inspect::inspect_commands())
|
||||||
|
.insert("recover", recover::recover_commands());
|
||||||
|
|
||||||
|
let rpcenv = CliEnvironment::new();
|
||||||
|
run_cli_command(cmd_def, rpcenv, Some(|future| pbs_runtime::main(future)));
|
||||||
|
}
|
@ -1,15 +0,0 @@
|
|||||||
use proxmox::api::cli::*;
|
|
||||||
|
|
||||||
mod proxmox_backup_debug;
|
|
||||||
use proxmox_backup_debug::{inspect_commands, recover_commands};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
proxmox_backup::tools::setup_safe_path_env();
|
|
||||||
|
|
||||||
let cmd_def = CliCommandMap::new()
|
|
||||||
.insert("inspect", inspect_commands())
|
|
||||||
.insert("recover", recover_commands());
|
|
||||||
|
|
||||||
let rpcenv = CliEnvironment::new();
|
|
||||||
run_cli_command(cmd_def, rpcenv, Some(|future| pbs_runtime::main(future)));
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
mod inspect;
|
|
||||||
pub use inspect::*;
|
|
||||||
mod recover;
|
|
||||||
pub use recover::*;
|
|
@ -2,10 +2,7 @@
|
|||||||
//!
|
//!
|
||||||
//! This is a collection of small and useful tools.
|
//! This is a collection of small and useful tools.
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::fs::File;
|
|
||||||
use std::io::{stdout, Write};
|
|
||||||
use std::os::unix::io::RawFd;
|
use std::os::unix::io::RawFd;
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
use openssl::hash::{hash, DigestBytes, MessageDigest};
|
use openssl::hash::{hash, DigestBytes, MessageDigest};
|
||||||
@ -227,13 +224,3 @@ pub fn create_run_dir() -> Result<(), Error> {
|
|||||||
let _: bool = create_path(pbs_buildcfg::PROXMOX_BACKUP_RUN_DIR_M!(), None, Some(opts))?;
|
let _: bool = create_path(pbs_buildcfg::PROXMOX_BACKUP_RUN_DIR_M!(), None, Some(opts))?;
|
||||||
Ok(())
|
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>)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user