summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-06 09:20:03 +0300
committerLars Wirzenius <liw@liw.fi>2021-04-06 09:36:07 +0300
commitab2432645aa99bc77632a5f4d497f1b6ee65ff92 (patch)
treeecdc94e803126946809c45ba5eca5d483cfebe76
parentc8d7fbf64fa99b5aeac5bdb0c360767951703166 (diff)
downloadobnam2-ab2432645aa99bc77632a5f4d497f1b6ee65ff92.tar.gz
refactor: clean up initial and incremental backup code paths a bit
-rw-r--r--src/cmd/backup.rs30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/cmd/backup.rs b/src/cmd/backup.rs
index b3e77c6..e6781e9 100644
--- a/src/cmd/backup.rs
+++ b/src/cmd/backup.rs
@@ -7,6 +7,7 @@ use crate::fsiter::FsIterator;
use crate::generation::NascentGeneration;
use bytesize::MIB;
use log::info;
+use std::path::Path;
use std::time::SystemTime;
use tempfile::NamedTempFile;
@@ -49,13 +50,11 @@ fn initial_backup(
config: &ClientConfig,
client: &BackupClient,
) -> Result<(ChunkId, i64, Vec<BackupError>), ObnamError> {
- let run = InitialBackup::new(config, &client)?;
+ info!("fresh backup without a previous generation");
let newtemp = NamedTempFile::new()?;
+ let run = InitialBackup::new(config, &client)?;
let mut all_warnings = vec![];
let count = {
- println!("create nascent");
- info!("fresh backup without a previous generation");
-
let mut new = NascentGeneration::create(newtemp.path())?;
for root in &config.roots {
let iter = FsIterator::new(root);
@@ -68,10 +67,7 @@ fn initial_backup(
};
run.drop();
- let progress = BackupProgress::upload_generation();
- let gen_id = client.upload_generation(newtemp.path(), SQLITE_CHUNK_SIZE)?;
- progress.finish();
-
+ let gen_id = upload_nascent_generation(client, newtemp.path())?;
Ok((gen_id, count, all_warnings))
}
@@ -80,13 +76,12 @@ fn incremental_backup(
config: &ClientConfig,
client: &BackupClient,
) -> Result<(ChunkId, i64, Vec<BackupError>), ObnamError> {
- let mut run = IncrementalBackup::new(config, &client)?;
+ info!("incremental backup based on {}", old_ref);
let newtemp = NamedTempFile::new()?;
+ let mut run = IncrementalBackup::new(config, &client)?;
let mut all_warnings = vec![];
let count = {
- info!("incremental backup based on {}", old_ref);
let oldtemp = NamedTempFile::new()?;
-
let old = run.fetch_previous_generation(old_ref, oldtemp.path())?;
run.start_backup(&old)?;
let mut new = NascentGeneration::create(newtemp.path())?;
@@ -101,9 +96,16 @@ fn incremental_backup(
};
run.drop();
+ let gen_id = upload_nascent_generation(client, newtemp.path())?;
+ Ok((gen_id, count, all_warnings))
+}
+
+fn upload_nascent_generation(
+ client: &BackupClient,
+ filename: &Path,
+) -> Result<ChunkId, ObnamError> {
let progress = BackupProgress::upload_generation();
- let gen_id = client.upload_generation(newtemp.path(), SQLITE_CHUNK_SIZE)?;
+ let gen_id = client.upload_generation(filename, SQLITE_CHUNK_SIZE)?;
progress.finish();
-
- Ok((gen_id, count, all_warnings))
+ Ok(gen_id)
}