src/backup/datastore.rs: add helpers to load/store manifest
We want this to modify the manifest "unprotected" data, for example to add upload statistics, notes, ...
This commit is contained in:
parent
32dc4c4604
commit
e443902583
@ -7,6 +7,9 @@ use std::convert::TryFrom;
|
|||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
use proxmox::tools::fs::{replace_file, CreateOptions};
|
||||||
|
|
||||||
use super::backup_info::{BackupGroup, BackupGroupGuard, BackupDir, BackupInfo};
|
use super::backup_info::{BackupGroup, BackupGroupGuard, BackupDir, BackupInfo};
|
||||||
use super::chunk_store::ChunkStore;
|
use super::chunk_store::ChunkStore;
|
||||||
@ -558,6 +561,7 @@ impl DataStore {
|
|||||||
}).map_err(|err| format_err!("unable to load blob '{:?}' - {}", path, err))
|
}).map_err(|err| format_err!("unable to load blob '{:?}' - {}", path, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn load_chunk(&self, digest: &[u8; 32]) -> Result<DataBlob, Error> {
|
pub fn load_chunk(&self, digest: &[u8; 32]) -> Result<DataBlob, Error> {
|
||||||
|
|
||||||
let (chunk_path, digest_str) = self.chunk_store.chunk_path(digest);
|
let (chunk_path, digest_str) = self.chunk_store.chunk_path(digest);
|
||||||
@ -583,4 +587,32 @@ impl DataStore {
|
|||||||
let manifest = BackupManifest::try_from(blob)?;
|
let manifest = BackupManifest::try_from(blob)?;
|
||||||
Ok((manifest, crypt_mode, raw_size))
|
Ok((manifest, crypt_mode, raw_size))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn load_manifest_json(
|
||||||
|
&self,
|
||||||
|
backup_dir: &BackupDir,
|
||||||
|
) -> Result<Value, Error> {
|
||||||
|
let blob = self.load_blob(backup_dir, MANIFEST_BLOB_NAME)?;
|
||||||
|
let manifest_data = blob.decode(None)?;
|
||||||
|
let manifest: Value = serde_json::from_slice(&manifest_data[..])?;
|
||||||
|
Ok(manifest)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn store_manifest(
|
||||||
|
&self,
|
||||||
|
backup_dir: &BackupDir,
|
||||||
|
manifest: Value,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let manifest = serde_json::to_string_pretty(&manifest)?;
|
||||||
|
let blob = DataBlob::encode(manifest.as_bytes(), None, true)?;
|
||||||
|
let raw_data = blob.raw_data();
|
||||||
|
|
||||||
|
let mut path = self.base_path();
|
||||||
|
path.push(backup_dir.relative_path());
|
||||||
|
path.push(MANIFEST_BLOB_NAME);
|
||||||
|
|
||||||
|
replace_file(&path, raw_data, CreateOptions::new())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user