src/api2/admin/datastore/backup.rs: add debug flag
This commit is contained in:
parent
976595e1a9
commit
a42d1f55c3
@ -35,6 +35,7 @@ pub fn api_method_upgrade_backup() -> ApiAsyncMethod {
|
||||
.required("backup-type", StringSchema::new("Backup type.")
|
||||
.format(Arc::new(ApiStringFormat::Enum(&["vm", "ct", "host"]))))
|
||||
.required("backup-id", StringSchema::new("Backup ID."))
|
||||
.optional("debug", BooleanSchema::new("Enable verbose debug logging."))
|
||||
)
|
||||
}
|
||||
|
||||
@ -48,6 +49,8 @@ fn upgrade_to_backup_protocol(
|
||||
|
||||
static PROXMOX_BACKUP_PROTOCOL_ID: &str = "proxmox-backup-protocol-h2";
|
||||
|
||||
let debug = param["debug"].as_bool().unwrap_or(false);
|
||||
|
||||
let store = tools::required_string_param(¶m, "store")?.to_owned();
|
||||
let datastore = DataStore::lookup_datastore(&store)?;
|
||||
|
||||
@ -85,21 +88,23 @@ fn upgrade_to_backup_protocol(
|
||||
let mut env = BackupEnvironment::new(
|
||||
env_type, username.clone(), worker.clone(), datastore, backup_dir);
|
||||
|
||||
env.debug = debug;
|
||||
env.last_backup = last_backup;
|
||||
|
||||
env.log(format!("starting new backup on datastore '{}': {:?}", store, path));
|
||||
|
||||
let service = BackupService::new(env.clone(), worker.clone());
|
||||
let service = BackupService::new(env.clone(), worker.clone(), debug);
|
||||
|
||||
let abort_future = worker.abort_future();
|
||||
|
||||
let env2 = env.clone();
|
||||
let env3 = env.clone();
|
||||
|
||||
req_body
|
||||
.on_upgrade()
|
||||
.map_err(Error::from)
|
||||
.and_then(move |conn| {
|
||||
worker.log("upgrade done");
|
||||
env3.debug("protocol upgrade done");
|
||||
|
||||
let mut http = hyper::server::conn::Http::new();
|
||||
http.http2_only(true);
|
||||
|
@ -58,6 +58,7 @@ pub struct BackupEnvironment {
|
||||
env_type: RpcEnvironmentType,
|
||||
result_attributes: HashMap<String, Value>,
|
||||
user: String,
|
||||
pub debug: bool,
|
||||
pub formatter: &'static OutputFormatter,
|
||||
pub worker: Arc<WorkerTask>,
|
||||
pub datastore: Arc<DataStore>,
|
||||
@ -89,6 +90,7 @@ impl BackupEnvironment {
|
||||
user,
|
||||
worker,
|
||||
datastore,
|
||||
debug: false,
|
||||
formatter: &JSON_FORMATTER,
|
||||
backup_dir,
|
||||
last_backup: None,
|
||||
@ -269,6 +271,10 @@ impl BackupEnvironment {
|
||||
self.worker.log(msg);
|
||||
}
|
||||
|
||||
pub fn debug<S: AsRef<str>>(&self, msg: S) {
|
||||
if self.debug { self.worker.log(msg); }
|
||||
}
|
||||
|
||||
pub fn format_response(&self, result: Result<Value, Error>) -> Response<Body> {
|
||||
match result {
|
||||
Ok(data) => (self.formatter.format_data)(data, self),
|
||||
|
@ -18,16 +18,20 @@ lazy_static!{
|
||||
static ref BACKUP_ROUTER: Router = super::backup_api();
|
||||
}
|
||||
|
||||
|
||||
pub struct BackupService {
|
||||
rpcenv: BackupEnvironment,
|
||||
worker: Arc<WorkerTask>,
|
||||
debug: bool,
|
||||
}
|
||||
|
||||
impl BackupService {
|
||||
|
||||
pub fn new(rpcenv: BackupEnvironment, worker: Arc<WorkerTask>) -> Self {
|
||||
Self { rpcenv, worker }
|
||||
pub fn new(rpcenv: BackupEnvironment, worker: Arc<WorkerTask>, debug: bool) -> Self {
|
||||
Self { rpcenv, worker, debug }
|
||||
}
|
||||
|
||||
pub fn debug<S: AsRef<str>>(&self, msg: S) {
|
||||
if self.debug { self.worker.log(msg); }
|
||||
}
|
||||
|
||||
fn handle_request(&self, req: Request<Body>) -> BoxFut {
|
||||
@ -41,8 +45,7 @@ impl BackupService {
|
||||
Err(err) => return Box::new(future::err(http_err!(BAD_REQUEST, err.to_string()))),
|
||||
};
|
||||
|
||||
self.worker.log(format!("H2 REQUEST {} {}", method, path));
|
||||
self.worker.log(format!("H2 COMPO {:?}", components));
|
||||
self.debug(format!("REQUEST: {} {}", method, path));
|
||||
|
||||
let mut uri_param = HashMap::new();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user