diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-08-10 10:42:32 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-08-16 13:18:07 +0300 |
commit | 3adfd67831f0e197b8b2e23c79393056584f398e (patch) | |
tree | afcbc8b48397ef4a8018c9c739ad567871586b6b /src/cmd/backup.rs | |
parent | 67757758f0226c31b667a329be6ab25008ef372a (diff) | |
download | obnam2-3adfd67831f0e197b8b2e23c79393056584f398e.tar.gz |
refactor: move file reading, etc, for backups to backup_run
Move code to read a file as chunks during a backup, and upload any new
chunks to the chunk server, into `src/backup_run.rs`. Previously they
were mostly in `src/client.rs`, which is meant to provide an
abstraction for using the chunk server API.
Sponsored-by: author
Diffstat (limited to 'src/cmd/backup.rs')
-rw-r--r-- | src/cmd/backup.rs | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/src/cmd/backup.rs b/src/cmd/backup.rs index dc03ddf..8f3d6d5 100644 --- a/src/cmd/backup.rs +++ b/src/cmd/backup.rs @@ -1,19 +1,15 @@ -use crate::backup_progress::BackupProgress; use crate::backup_run::BackupRun; -use crate::chunkid::ChunkId; use crate::client::AsyncBackupClient; use crate::config::ClientConfig; use crate::error::ObnamError; -use bytesize::MIB; +use crate::generation::GenId; + use log::info; -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; - #[derive(Debug, StructOpt)] pub struct Backup {} @@ -47,8 +43,6 @@ impl Backup { } }; - let gen_id = upload_nascent_generation(&client, newtemp.path()).await?; - for w in outcome.warnings.iter() { println!("warning: {}", w); } @@ -64,7 +58,7 @@ impl Backup { report_stats( &runtime, outcome.files_count, - &gen_id, + &outcome.gen_id, outcome.warnings.len(), )?; @@ -79,7 +73,7 @@ impl Backup { fn report_stats( runtime: &SystemTime, file_count: i64, - gen_id: &ChunkId, + gen_id: &GenId, num_warnings: usize, ) -> Result<(), ObnamError> { println!("status: OK"); @@ -89,15 +83,3 @@ fn report_stats( println!("generation-id: {}", gen_id); Ok(()) } - -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) - .await?; - progress.finish(); - Ok(gen_id) -} |