summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-02-07 18:03:16 +0200
committerLars Wirzenius <liw@liw.fi>2021-02-07 18:45:29 +0200
commit3ef5bd7a3ab445509216116bb2f8009ace2b1080 (patch)
treef9a176737e6b79f9c6977bdf98090041bca2f01e /src
parent5b863edb32314808b6823f90c03ad97da6fdbcbf (diff)
downloadobnam2-3ef5bd7a3ab445509216116bb2f8009ace2b1080.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/backup_reason.rs3
-rw-r--r--src/backup_run.rs30
-rw-r--r--src/cmd/restore.rs6
3 files changed, 29 insertions, 10 deletions
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<ChunkId>, 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() {