From 1369bcdbbad0cbf4c5d97785b0580a6bb444ea69 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 16 Apr 2021 12:20:44 +0200 Subject: [PATCH] tape restore: verify if all chunks exist --- src/api2/tape/restore.rs | 8 ++++++-- src/backup/datastore.rs | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs index d6903d40..5cadd6dd 100644 --- a/src/api2/tape/restore.rs +++ b/src/api2/tape/restore.rs @@ -516,7 +516,7 @@ fn restore_archive<'a>( if is_new { task_log!(worker, "restore snapshot {}", backup_dir); - match restore_snapshot_archive(worker, reader, &path) { + match restore_snapshot_archive(worker, reader, &path, &datastore) { Err(err) => { std::fs::remove_dir_all(&path)?; bail!("restore snapshot {} failed - {}", backup_dir, err); @@ -667,10 +667,11 @@ fn restore_snapshot_archive<'a>( worker: &WorkerTask, reader: Box, snapshot_path: &Path, + datastore: &DataStore, ) -> Result { let mut decoder = pxar::decoder::sync::Decoder::from_std(reader)?; - match try_restore_snapshot_archive(worker, &mut decoder, snapshot_path) { + match try_restore_snapshot_archive(worker, &mut decoder, snapshot_path, datastore) { Ok(()) => Ok(true), Err(err) => { let reader = decoder.input(); @@ -695,6 +696,7 @@ fn try_restore_snapshot_archive( worker: &WorkerTask, decoder: &mut pxar::decoder::sync::Decoder, snapshot_path: &Path, + datastore: &DataStore, ) -> Result<(), Error> { let _root = match decoder.next() { @@ -785,11 +787,13 @@ fn try_restore_snapshot_archive( let index = DynamicIndexReader::open(&archive_path)?; let (csum, size) = index.compute_csum(); manifest.verify_file(&item.filename, &csum, size)?; + datastore.fast_index_verification(&index)?; } ArchiveType::FixedIndex => { let index = FixedIndexReader::open(&archive_path)?; let (csum, size) = index.compute_csum(); manifest.verify_file(&item.filename, &csum, size)?; + datastore.fast_index_verification(&index)?; } ArchiveType::Blob => { let mut tmpfile = std::fs::File::open(&archive_path)?; diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 8162c269..d631bdcd 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -153,6 +153,24 @@ impl DataStore { Ok(out) } + /// Fast index verification - only check if chunks exists + pub fn fast_index_verification(&self, index: &dyn IndexFile) -> Result<(), Error> { + + for pos in 0..index.index_count() { + let info = index.chunk_info(pos).unwrap(); + self.stat_chunk(&info.digest). + map_err(|err| { + format_err!( + "fast_index_verification error, stat_chunk {} failed - {}", + proxmox::tools::digest_to_hex(&info.digest), + err, + ) + })?; + } + + Ok(()) + } + pub fn name(&self) -> &str { self.chunk_store.name() } @@ -786,4 +804,3 @@ impl DataStore { self.verify_new } } -