summaryrefslogtreecommitdiff
path: root/src/cmd/backup.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-08-08 15:03:31 +0300
committerLars Wirzenius <liw@liw.fi>2021-08-09 09:58:38 +0300
commit6e9a1f5f45a5608a05931fd4d579c8ab52316f55 (patch)
treec33ff750c17eb6ca7c7d6771c885da2f31c40cd3 /src/cmd/backup.rs
parent30c20dcf3d81e9147e2bd4617bd055a5a8a17896 (diff)
downloadobnam2-6e9a1f5f45a5608a05931fd4d579c8ab52316f55.tar.gz
refactor: use async for "obnam backup"
This changes things so that "obnam backup" uses async for everything. The old non-async BackupClient and ChunkClient are dropped. This does NOT move the chunking, and checksum computation, to its own function. This will happen later. Sponsored-by: author
Diffstat (limited to 'src/cmd/backup.rs')
-rw-r--r--src/cmd/backup.rs30
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)
}