2019-06-29 11:43:10 +00:00
|
|
|
use std::io::Write;
|
|
|
|
|
2020-04-17 12:11:25 +00:00
|
|
|
use anyhow::{Error};
|
2019-08-28 13:30:25 +00:00
|
|
|
|
2020-10-08 13:19:39 +00:00
|
|
|
use proxmox_backup::api2::types::Authid;
|
2020-01-25 11:18:00 +00:00
|
|
|
use proxmox_backup::client::{HttpClient, HttpClientOptions, BackupReader};
|
2019-06-29 11:43:10 +00:00
|
|
|
|
|
|
|
pub struct DummyWriter {
|
|
|
|
bytes: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Write for DummyWriter {
|
|
|
|
|
|
|
|
fn write(&mut self, data: &[u8]) -> Result<usize, std::io::Error> {
|
|
|
|
self.bytes += data.len();
|
|
|
|
Ok(data.len())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn flush(&mut self) -> Result<(), std::io::Error> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-28 13:30:25 +00:00
|
|
|
async fn run() -> Result<(), Error> {
|
2019-06-29 11:43:10 +00:00
|
|
|
|
|
|
|
let host = "localhost";
|
|
|
|
|
2020-10-08 13:19:39 +00:00
|
|
|
let auth_id = Authid::root_auth_id();
|
2019-06-29 11:43:10 +00:00
|
|
|
|
2020-01-25 11:18:00 +00:00
|
|
|
let options = HttpClientOptions::new()
|
|
|
|
.interactive(true)
|
|
|
|
.ticket_cache(true);
|
|
|
|
|
2020-10-08 13:19:39 +00:00
|
|
|
let client = HttpClient::new(host, 8007, auth_id, options)?;
|
2019-06-29 11:43:10 +00:00
|
|
|
|
2020-09-12 13:10:47 +00:00
|
|
|
let backup_time = proxmox::tools::time::parse_rfc3339("2019-06-28T10:49:48Z")?;
|
2019-06-29 11:43:10 +00:00
|
|
|
|
2019-10-12 13:50:26 +00:00
|
|
|
let client = BackupReader::start(client, None, "store2", "host", "elsa", backup_time, true)
|
2019-08-28 13:30:25 +00:00
|
|
|
.await?;
|
2019-06-29 11:43:10 +00:00
|
|
|
|
|
|
|
let start = std::time::SystemTime::now();
|
|
|
|
|
2019-08-28 13:30:25 +00:00
|
|
|
let mut bytes = 0;
|
|
|
|
for _ in 0..100 {
|
2020-06-12 09:46:42 +00:00
|
|
|
let mut writer = DummyWriter { bytes: 0 };
|
|
|
|
client.speedtest(&mut writer).await?;
|
2019-08-28 13:30:25 +00:00
|
|
|
println!("Received {} bytes", writer.bytes);
|
|
|
|
bytes += writer.bytes;
|
|
|
|
}
|
2019-06-29 11:43:10 +00:00
|
|
|
|
2019-08-28 13:30:25 +00:00
|
|
|
let elapsed = start.elapsed().unwrap();
|
|
|
|
let elapsed = (elapsed.as_secs() as f64) +
|
|
|
|
(elapsed.subsec_millis() as f64)/1000.0;
|
2019-06-29 11:43:10 +00:00
|
|
|
|
2019-08-28 13:30:25 +00:00
|
|
|
println!("Downloaded {} bytes, {} MB/s", bytes, (bytes as f64)/(elapsed*1024.0*1024.0));
|
2019-06-29 11:43:10 +00:00
|
|
|
|
2019-08-28 13:30:25 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2019-06-29 11:43:10 +00:00
|
|
|
|
2020-06-22 14:44:14 +00:00
|
|
|
fn main() {
|
2020-01-20 11:52:22 +00:00
|
|
|
if let Err(err) = proxmox_backup::tools::runtime::main(run()) {
|
2019-08-28 13:30:25 +00:00
|
|
|
eprintln!("ERROR: {}", err);
|
|
|
|
}
|
|
|
|
println!("DONE");
|
2019-06-29 11:43:10 +00:00
|
|
|
}
|