From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/3] backup/datastore: save garbage collection status to disk
Date: Fri, 23 Oct 2020 16:32:32 +0200 [thread overview]
Message-ID: <20201023143233.14949-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20201023143233.14949-1-d.csapak@proxmox.com>
and load it again when opening it
this way we can persist the status of the last garbage collect across
daemon reloads and reboots
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/backup/datastore.rs | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs
index 2389cc6c..485a10ff 100644
--- a/src/backup/datastore.rs
+++ b/src/backup/datastore.rs
@@ -9,7 +9,7 @@ use std::fs::File;
use anyhow::{bail, format_err, Error};
use lazy_static::lazy_static;
-use proxmox::tools::fs::{replace_file, CreateOptions, open_file_locked};
+use proxmox::tools::fs::{replace_file, file_read_optional_string, CreateOptions, open_file_locked};
use super::backup_info::{BackupGroup, BackupDir};
use super::chunk_store::ChunkStore;
@@ -71,7 +71,20 @@ impl DataStore {
fn open_with_path(store_name: &str, path: &Path, config: DataStoreConfig) -> Result<Self, Error> {
let chunk_store = ChunkStore::open(store_name, path)?;
- let gc_status = GarbageCollectionStatus::default();
+ let mut gc_status_path = chunk_store.base_path();
+ gc_status_path.push(".gc-status");
+
+ let gc_status = if let Some(state) = file_read_optional_string(gc_status_path)? {
+ match serde_json::from_str(&state) {
+ Ok(state) => state,
+ Err(err) => {
+ eprintln!("error reading gc-status: {}", err);
+ GarbageCollectionStatus::default()
+ }
+ }
+ } else {
+ GarbageCollectionStatus::default()
+ };
Ok(Self {
chunk_store: Arc::new(chunk_store),
@@ -572,6 +585,23 @@ impl DataStore {
crate::task_log!(worker, "Average chunk size: {}", HumanByte::from(avg_chunk));
}
+ if let Ok(serialized) = serde_json::to_string(&gc_status) {
+ let mut path = self.base_path();
+ path.push(".gc-status");
+
+ let backup_user = crate::backup::backup_user()?;
+ let mode = nix::sys::stat::Mode::from_bits_truncate(0o0644);
+ // set the correct owner/group/permissions while saving file
+ // owner(rw) = backup, group(r)= backup
+ let options = CreateOptions::new()
+ .perm(mode)
+ .owner(backup_user.uid)
+ .group(backup_user.gid);
+
+ // ignore errors
+ let _ = replace_file(path, serialized.as_bytes(), options);
+ }
+
*self.last_gc_status.lock().unwrap() = gc_status;
} else {
--
2.20.1
next prev parent reply other threads:[~2020-10-23 14:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-23 14:32 [pbs-devel] [PATCH proxmox-backup 0/3] improve and extend admin/datastore/status api Dominik Csapak
2020-10-23 14:32 ` [pbs-devel] [PATCH proxmox-backup 1/3] backup/datastore: count still bad chunks for the status Dominik Csapak
2020-10-23 14:32 ` Dominik Csapak [this message]
2020-10-23 14:32 ` [pbs-devel] [PATCH proxmox-backup 3/3] admin/datastore: add more info to status call Dominik Csapak
2020-11-03 5:52 ` Dietmar Maurer
2020-11-03 6:53 ` Dominik Csapak
2020-10-27 16:44 ` [pbs-devel] applied-series: [PATCH proxmox-backup 0/3] improve and extend admin/datastore/status api Thomas Lamprecht
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=20201023143233.14949-3-d.csapak@proxmox.com \
--to=d.csapak@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