2020-07-02 12:00:32 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use anyhow::{Error};
|
|
|
|
use serde_json::Value;
|
|
|
|
use chrono::{TimeZone, Utc};
|
|
|
|
|
|
|
|
use proxmox::api::{ApiMethod, RpcEnvironment};
|
|
|
|
use proxmox::api::api;
|
|
|
|
|
|
|
|
use proxmox_backup::backup::{
|
|
|
|
load_and_decrypt_key,
|
|
|
|
CryptConfig,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
use proxmox_backup::client::*;
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
KEYFILE_SCHEMA, REPO_URL_SCHEMA,
|
|
|
|
extract_repository_from_value,
|
|
|
|
record_repository,
|
|
|
|
connect,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[api(
|
|
|
|
input: {
|
|
|
|
properties: {
|
|
|
|
repository: {
|
|
|
|
schema: REPO_URL_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
2020-07-09 14:16:39 +00:00
|
|
|
verbose: {
|
|
|
|
description: "Verbose output.",
|
|
|
|
type: bool,
|
|
|
|
optional: true,
|
|
|
|
},
|
2020-07-02 12:00:32 +00:00
|
|
|
keyfile: {
|
|
|
|
schema: KEYFILE_SCHEMA,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)]
|
|
|
|
/// Run benchmark tests
|
|
|
|
pub async fn benchmark(
|
|
|
|
param: Value,
|
|
|
|
_info: &ApiMethod,
|
|
|
|
_rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
|
|
|
let repo = extract_repository_from_value(¶m)?;
|
|
|
|
|
|
|
|
let keyfile = param["keyfile"].as_str().map(PathBuf::from);
|
|
|
|
|
2020-07-09 14:16:39 +00:00
|
|
|
let verbose = param["verbose"].as_bool().unwrap_or(false);
|
|
|
|
|
2020-07-02 12:00:32 +00:00
|
|
|
let crypt_config = match keyfile {
|
|
|
|
None => None,
|
|
|
|
Some(path) => {
|
2020-07-06 09:39:24 +00:00
|
|
|
let (key, _) = load_and_decrypt_key(&path, &crate::key::get_encryption_key_password)?;
|
2020-07-02 12:00:32 +00:00
|
|
|
let crypt_config = CryptConfig::new(key)?;
|
|
|
|
Some(Arc::new(crypt_config))
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let backup_time = Utc.timestamp(Utc::now().timestamp(), 0);
|
|
|
|
|
|
|
|
let client = connect(repo.host(), repo.user())?;
|
|
|
|
record_repository(&repo);
|
|
|
|
|
2020-07-09 14:16:39 +00:00
|
|
|
println!("Connecting to backup server");
|
2020-07-02 12:00:32 +00:00
|
|
|
let client = BackupWriter::start(
|
|
|
|
client,
|
|
|
|
crypt_config.clone(),
|
|
|
|
repo.store(),
|
|
|
|
"host",
|
2020-07-09 14:16:39 +00:00
|
|
|
"benchmark",
|
2020-07-02 12:00:32 +00:00
|
|
|
backup_time,
|
|
|
|
false,
|
|
|
|
).await?;
|
|
|
|
|
|
|
|
println!("Start upload speed test");
|
2020-07-09 14:16:39 +00:00
|
|
|
let speed = client.upload_speedtest(verbose).await?;
|
2020-07-02 12:00:32 +00:00
|
|
|
|
|
|
|
println!("Upload speed: {} MiB/s", speed);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|