From ad98db921aa3d710ad7c448c6a1b818f4359d73a Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 6 Feb 2021 18:03:49 +0200 Subject: feat: use the chunk size setting from the client configuration Use the chunk_size setting for file data. For the SQLite file, use a hard-coded size instead. --- src/backup_run.rs | 4 ++-- src/bin/obnam.rs | 8 ++------ src/cmd/backup.rs | 10 +++++++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/backup_run.rs b/src/backup_run.rs index 05d5988..fce9a73 100644 --- a/src/backup_run.rs +++ b/src/backup_run.rs @@ -30,14 +30,14 @@ pub enum BackupError { pub type BackupResult = Result; impl BackupRun { - pub fn new(config: &ClientConfig, buffer_size: usize) -> BackupResult { + pub fn new(config: &ClientConfig) -> BackupResult { let client = BackupClient::new(config)?; let policy = BackupPolicy::new(); let progress = BackupProgress::new(); Ok(Self { client, policy, - buffer_size, + buffer_size: config.chunk_size, progress, }) } diff --git a/src/bin/obnam.rs b/src/bin/obnam.rs index 9c5d3f4..8778a73 100644 --- a/src/bin/obnam.rs +++ b/src/bin/obnam.rs @@ -6,8 +6,6 @@ use obnam::cmd::{backup, get_chunk, list, list_files, restore, show_config, show use std::path::{Path, PathBuf}; use structopt::StructOpt; -const BUFFER_SIZE: usize = 1024 * 1024; - fn main() -> anyhow::Result<()> { let opt = Opt::from_args(); let config_file = match opt.config { @@ -15,15 +13,13 @@ fn main() -> anyhow::Result<()> { Some(ref path) => path.to_path_buf(), }; let config = ClientConfig::read_config(&config_file)?; - if let Some(ref log) = config.log { - setup_logging(&log)?; - } + setup_logging(&config.log)?; info!("client starts"); debug!("{:?}", opt); let result = match opt.cmd { - Command::Backup => backup(&config, BUFFER_SIZE), + Command::Backup => backup(&config), Command::List => list(&config), Command::ShowGeneration { gen_id } => show_generation(&config, &gen_id), Command::ListFiles { gen_id } => list_files(&config, &gen_id), diff --git a/src/cmd/backup.rs b/src/cmd/backup.rs index a43a622..fd1d876 100644 --- a/src/cmd/backup.rs +++ b/src/cmd/backup.rs @@ -7,10 +7,12 @@ use log::info; use std::time::SystemTime; use tempfile::NamedTempFile; -pub fn backup(config: &ClientConfig, buffer_size: usize) -> Result<(), ObnamError> { +const SQLITE_CHUNK_SIZE: usize = 1024 * 1024; + +pub fn backup(config: &ClientConfig) -> Result<(), ObnamError> { let runtime = SystemTime::now(); - let run = BackupRun::new(config, buffer_size)?; + let run = BackupRun::new(config)?; // Create a named temporary file. We don't meed the open file // handle, so we discard that. @@ -52,7 +54,9 @@ pub fn backup(config: &ClientConfig, buffer_size: usize) -> Result<(), ObnamErro // Upload the SQLite file, i.e., the named temporary file, which // still exists, since we persisted it above. - let gen_id = run.client().upload_generation(&newname, buffer_size)?; + let gen_id = run + .client() + .upload_generation(&newname, SQLITE_CHUNK_SIZE)?; println!("status: OK"); println!("duration: {}", runtime.elapsed()?.as_secs()); println!("file-count: {}", file_count); -- cgit v1.2.1