summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-02-06 18:03:49 +0200
committerLars Wirzenius <liw@liw.fi>2021-02-06 18:15:44 +0200
commitad98db921aa3d710ad7c448c6a1b818f4359d73a (patch)
tree19a0ed284970b895245a1133af51b8ec0b4b5015
parentf1d1636beeddd56635f248bd0eb2b5841c65f562 (diff)
downloadobnam2-ad98db921aa3d710ad7c448c6a1b818f4359d73a.tar.gz
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.
-rw-r--r--src/backup_run.rs4
-rw-r--r--src/bin/obnam.rs8
-rw-r--r--src/cmd/backup.rs10
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<T> = Result<T, BackupError>;
impl BackupRun {
- pub fn new(config: &ClientConfig, buffer_size: usize) -> BackupResult<Self> {
+ pub fn new(config: &ClientConfig) -> BackupResult<Self> {
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);