public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Reiter <s.reiter@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 5/5] backup: ensure base snapshots are still available after backup
Date: Wed, 29 Jul 2020 14:33:14 +0200	[thread overview]
Message-ID: <20200729123314.10049-6-s.reiter@proxmox.com> (raw)
In-Reply-To: <20200729123314.10049-1-s.reiter@proxmox.com>

This should never trigger if everything else works correctly, but it is
still a very cheap check to avoid wrongly marking a backup as "OK" when
in fact some chunks might be missing.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---
 src/api2/backup.rs             |  1 +
 src/api2/backup/environment.rs | 21 ++++++++++++++++++++-
 src/backup/backup_info.rs      |  2 +-
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/api2/backup.rs b/src/api2/backup.rs
index 621e8c07..b9dff1fc 100644
--- a/src/api2/backup.rs
+++ b/src/api2/backup.rs
@@ -660,6 +660,7 @@ fn download_previous(
             };
             if let Some(index) = index {
                 env.log(format!("register chunks in '{}' from previous backup.", archive_name));
+                env.register_base_snapshot(last_backup.backup_dir.clone());
 
                 for pos in 0..index.index_count() {
                     let info = index.chunk_info(pos).unwrap();
diff --git a/src/api2/backup/environment.rs b/src/api2/backup/environment.rs
index f2ebd24f..c8417ef9 100644
--- a/src/api2/backup/environment.rs
+++ b/src/api2/backup/environment.rs
@@ -1,6 +1,6 @@
 use anyhow::{bail, Error};
 use std::sync::{Arc, Mutex};
-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
 
 use serde_json::{json, Value};
 
@@ -57,6 +57,7 @@ struct SharedBackupState {
     dynamic_writers: HashMap<usize, DynamicWriterState>,
     fixed_writers: HashMap<usize, FixedWriterState>,
     known_chunks: HashMap<[u8;32], u32>,
+    base_snapshots: HashSet<BackupDir>,
 }
 
 impl SharedBackupState {
@@ -108,6 +109,7 @@ impl BackupEnvironment {
             dynamic_writers: HashMap::new(),
             fixed_writers: HashMap::new(),
             known_chunks: HashMap::new(),
+            base_snapshots: HashSet::new(),
         };
 
         Self {
@@ -124,6 +126,13 @@ impl BackupEnvironment {
         }
     }
 
+    /// Register a snapshot as a predecessor of the current backup.
+    /// It's existance will be ensured on finishing.
+    pub fn register_base_snapshot(&self, snap: BackupDir) {
+        let mut state = self.state.lock().unwrap();
+        state.base_snapshots.insert(snap);
+    }
+
     /// Register a Chunk with associated length.
     ///
     /// We do not fully trust clients, so a client may only use registered
@@ -445,6 +454,16 @@ impl BackupEnvironment {
             bail!("backup does not contain valid files (file count == 0)");
         }
 
+        for snap in &state.base_snapshots {
+            let path = self.datastore.snapshot_path(snap);
+            if !path.exists() {
+                bail!(
+                    "base snapshot {} was removed during backup, cannot finish as chunks might be missing",
+                    snap
+                );
+            }
+        }
+
         state.finished = true;
 
         Ok(())
diff --git a/src/backup/backup_info.rs b/src/backup/backup_info.rs
index 041f5785..e77cc787 100644
--- a/src/backup/backup_info.rs
+++ b/src/backup/backup_info.rs
@@ -217,7 +217,7 @@ impl std::str::FromStr for BackupGroup {
 /// Uniquely identify a Backup (relative to data store)
 ///
 /// We also call this a backup snaphost.
-#[derive(Debug, Eq, PartialEq, Clone)]
+#[derive(Debug, Eq, PartialEq, Hash, Clone)]
 pub struct BackupDir {
     /// Backup group
     group: BackupGroup,
-- 
2.20.1





  parent reply	other threads:[~2020-07-29 12:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-29 12:33 [pbs-devel] [PATCH 0/5] fix #2881: protect base snapshots and avoid races Stefan Reiter
2020-07-29 12:33 ` [pbs-devel] [PATCH proxmox-backup 1/5] fix typo: avgerage to average Stefan Reiter
2020-07-30  5:25   ` [pbs-devel] applied: " Dietmar Maurer
2020-07-29 12:33 ` [pbs-devel] [PATCH proxmox-backup 2/5] datastore: prevent deletion of snaps in use as "previous backup" Stefan Reiter
2020-07-30  6:37   ` [pbs-devel] applied: " Dietmar Maurer
2020-07-30  6:40   ` [pbs-devel] " Fabian Grünbichler
2020-07-29 12:33 ` [pbs-devel] [PATCH proxmox-backup 3/5] tools: add nonblocking mode to lock_file Stefan Reiter
2020-07-30  6:23   ` [pbs-devel] applied: " Dietmar Maurer
2020-07-29 12:33 ` [pbs-devel] [PATCH proxmox-backup 4/5] backup: use flock on backup group to forbid multiple backups at once Stefan Reiter
2020-07-30  5:50   ` Dietmar Maurer
2020-07-30  7:36     ` Stefan Reiter
2020-07-30  7:41       ` Dietmar Maurer
2020-07-30  8:02         ` Stefan Reiter
2020-07-30  6:38   ` [pbs-devel] applied: " Dietmar Maurer
2020-07-29 12:33 ` Stefan Reiter [this message]
2020-07-30  6:38   ` [pbs-devel] applied: [PATCH proxmox-backup 5/5] backup: ensure base snapshots are still available after backup Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200729123314.10049-6-s.reiter@proxmox.com \
    --to=s.reiter@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal