diff options
Diffstat (limited to 'src/cmd/backup.rs')
-rw-r--r-- | src/cmd/backup.rs | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/cmd/backup.rs b/src/cmd/backup.rs index 04dfb05..dc03ddf 100644 --- a/src/cmd/backup.rs +++ b/src/cmd/backup.rs @@ -1,7 +1,7 @@ use crate::backup_progress::BackupProgress; use crate::backup_run::BackupRun; use crate::chunkid::ChunkId; -use crate::client::BackupClient; +use crate::client::AsyncBackupClient; use crate::config::ClientConfig; use crate::error::ObnamError; use bytesize::MIB; @@ -10,6 +10,7 @@ use std::path::Path; use std::time::SystemTime; use structopt::StructOpt; use tempfile::NamedTempFile; +use tokio::runtime::Runtime; const SQLITE_CHUNK_SIZE: usize = MIB as usize; @@ -18,10 +19,15 @@ pub struct Backup {} impl Backup { pub fn run(&self, config: &ClientConfig) -> Result<(), ObnamError> { + let rt = Runtime::new()?; + rt.block_on(self.run_async(config)) + } + + async fn run_async(&self, config: &ClientConfig) -> Result<(), ObnamError> { let runtime = SystemTime::now(); - let client = BackupClient::new(config)?; - let genlist = client.list_generations()?; + let client = AsyncBackupClient::new(config)?; + let genlist = client.list_generations().await?; let oldtemp = NamedTempFile::new()?; let newtemp = NamedTempFile::new()?; @@ -30,18 +36,18 @@ impl Backup { Err(_) => { info!("fresh backup without a previous generation"); let mut run = BackupRun::initial(config, &client)?; - let old = run.start(None, oldtemp.path())?; - (false, run.backup_roots(config, &old, newtemp.path())?) + let old = run.start(None, oldtemp.path()).await?; + (false, run.backup_roots(config, &old, newtemp.path()).await?) } Ok(old_id) => { info!("incremental backup based on {}", old_id); let mut run = BackupRun::incremental(config, &client)?; - let old = run.start(Some(&old_id), oldtemp.path())?; - (true, run.backup_roots(config, &old, newtemp.path())?) + let old = run.start(Some(&old_id), oldtemp.path()).await?; + (true, run.backup_roots(config, &old, newtemp.path()).await?) } }; - let gen_id = upload_nascent_generation(&client, newtemp.path())?; + let gen_id = upload_nascent_generation(&client, newtemp.path()).await?; for w in outcome.warnings.iter() { println!("warning: {}", w); @@ -84,12 +90,14 @@ fn report_stats( Ok(()) } -fn upload_nascent_generation( - client: &BackupClient, +async fn upload_nascent_generation( + client: &AsyncBackupClient, filename: &Path, ) -> Result<ChunkId, ObnamError> { let progress = BackupProgress::upload_generation(); - let gen_id = client.upload_generation(filename, SQLITE_CHUNK_SIZE)?; + let gen_id = client + .upload_generation(filename, SQLITE_CHUNK_SIZE) + .await?; progress.finish(); Ok(gen_id) } |