From 3ef5bd7a3ab445509216116bb2f8009ace2b1080 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 7 Feb 2021 18:03:16 +0200 Subject: feat: if file can't be read, log that, don't end backup in error Such files won't be restored, as they'd be restored as empty file, and that would be confusing and thus bad. --- client.yaml | 2 +- src/backup_reason.rs | 3 +++ src/backup_run.rs | 30 +++++++++++++++++++++--------- src/cmd/restore.rs | 6 +++++- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/client.yaml b/client.yaml index 99feee4..a1a63e7 100644 --- a/client.yaml +++ b/client.yaml @@ -1,5 +1,5 @@ server_url: https://localhost:8888 verify_tls_cert: false roots: - - /home/liw/tmp/Foton + - x log: obnam.log diff --git a/src/backup_reason.rs b/src/backup_reason.rs index b3ce5e9..f785dea 100644 --- a/src/backup_reason.rs +++ b/src/backup_reason.rs @@ -9,6 +9,7 @@ pub enum Reason { Changed, Unchanged, GenerationLookupError, + FileError, Unknown, } @@ -20,6 +21,7 @@ impl Reason { "changed" => Reason::Changed, "unchanged" => Reason::Unchanged, "genlookuperror" => Reason::GenerationLookupError, + "fileerror" => Reason::FileError, _ => Reason::Unknown, } } @@ -42,6 +44,7 @@ impl fmt::Display for Reason { Reason::Changed => "changed", Reason::Unchanged => "unchanged", Reason::GenerationLookupError => "genlookuperror", + Reason::FileError => "fileerror", Reason::Unknown => "unknown", }; write!(f, "{}", reason) diff --git a/src/backup_run.rs b/src/backup_run.rs index e0ed533..7bb4440 100644 --- a/src/backup_run.rs +++ b/src/backup_run.rs @@ -7,6 +7,7 @@ use crate::fsiter::{FsIterError, FsIterResult}; use crate::generation::{LocalGeneration, LocalGenerationError}; use crate::policy::BackupPolicy; use log::{info, warn}; +use std::path::Path; pub struct BackupRun { client: BackupClient, @@ -60,10 +61,7 @@ impl BackupRun { let path = &entry.pathbuf(); info!("backup: {}", path.display()); self.progress.found_live_file(path); - let ids = self - .client - .upload_filesystem_entry(&entry, self.buffer_size)?; - Ok((entry.clone(), ids, Reason::IsNew)) + backup_file(&self.client, &entry, &path, self.buffer_size, Reason::IsNew) } } } @@ -89,12 +87,9 @@ impl BackupRun { | Reason::Changed | Reason::GenerationLookupError | Reason::Unknown => { - let ids = self - .client - .upload_filesystem_entry(&entry, self.buffer_size)?; - Ok((entry.clone(), ids, reason)) + backup_file(&self.client, &entry, &path, self.buffer_size, reason) } - Reason::Unchanged | Reason::Skipped => { + Reason::Unchanged | Reason::Skipped | Reason::FileError => { let fileno = old.get_fileno(&entry.pathbuf())?; let ids = if let Some(fileno) = fileno { old.chunkids(fileno)? @@ -108,3 +103,20 @@ impl BackupRun { } } } + +fn backup_file( + client: &BackupClient, + entry: &FilesystemEntry, + path: &Path, + chunk_size: usize, + reason: Reason, +) -> BackupResult<(FilesystemEntry, Vec, Reason)> { + let ids = client.upload_filesystem_entry(&entry, chunk_size); + match ids { + Err(err) => { + warn!("error backing up {}, skipping it: {}", path.display(), err); + Ok((entry.clone(), vec![], Reason::FileError)) + } + Ok(ids) => Ok((entry.clone(), ids, reason)), + } +} diff --git a/src/cmd/restore.rs b/src/cmd/restore.rs index a0f5ec0..5d01bd4 100644 --- a/src/cmd/restore.rs +++ b/src/cmd/restore.rs @@ -1,3 +1,4 @@ +use crate::backup_reason::Reason; use crate::client::ClientConfig; use crate::client::{BackupClient, ClientError}; use crate::error::ObnamError; @@ -35,7 +36,10 @@ pub fn restore(config: &ClientConfig, gen_ref: &str, to: &Path) -> Result<(), Ob info!("restoring {} files", gen.file_count()?); let progress = create_progress_bar(gen.file_count()?, true); for file in gen.files()? { - restore_generation(&client, &gen, file.fileno(), file.entry(), &to, &progress)?; + match file.reason() { + Reason::FileError => (), + _ => restore_generation(&client, &gen, file.fileno(), file.entry(), &to, &progress)?, + } } for file in gen.files()? { if file.entry().is_dir() { -- cgit v1.2.1