From c8fff67d88fa3d7ac750e2c8d948465bc0e3bf11 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 31 Jul 2020 07:27:57 +0200 Subject: [PATCH] finish_backup: add chunk_upload_stats to manifest --- src/api2/backup/environment.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/api2/backup/environment.rs b/src/api2/backup/environment.rs index 59247283..c632efcb 100644 --- a/src/api2/backup/environment.rs +++ b/src/api2/backup/environment.rs @@ -2,6 +2,7 @@ use anyhow::{bail, format_err, Error}; use std::sync::{Arc, Mutex}; use std::collections::{HashMap, HashSet}; +use ::serde::{Serialize}; use serde_json::{json, Value}; use proxmox::tools::digest_to_hex; @@ -13,6 +14,7 @@ use crate::backup::*; use crate::server::formatter::*; use hyper::{Body, Response}; +#[derive(Copy, Clone, Serialize)] struct UploadStatistic { count: u64, size: u64, @@ -31,6 +33,19 @@ impl UploadStatistic { } } +impl std::ops::Add for UploadStatistic { + type Output = Self; + + fn add(self, other: Self) -> Self { + Self { + count: self.count + other.count, + size: self.size + other.size, + compressed_size: self.compressed_size + other.compressed_size, + duplicates: self.duplicates + other.duplicates, + } + } +} + struct DynamicWriterState { name: String, index: DynamicIndexWriter, @@ -58,6 +73,8 @@ struct SharedBackupState { fixed_writers: HashMap, known_chunks: HashMap<[u8;32], u32>, base_snapshots: HashSet, + backup_size: u64, // sums up size of all files + backup_stat: UploadStatistic, } impl SharedBackupState { @@ -110,6 +127,8 @@ impl BackupEnvironment { fixed_writers: HashMap::new(), known_chunks: HashMap::new(), base_snapshots: HashSet::new(), + backup_size: 0, + backup_stat: UploadStatistic::new(), }; Self { @@ -370,6 +389,8 @@ impl BackupEnvironment { self.log_upload_stat(&data.name, &csum, &uuid, size, chunk_count, &data.upload_stat); state.file_counter += 1; + state.backup_size += size; + state.backup_stat = state.backup_stat + data.upload_stat; Ok(()) } @@ -412,6 +433,8 @@ impl BackupEnvironment { self.log_upload_stat(&data.name, &expected_csum, &uuid, size, chunk_count, &data.upload_stat); state.file_counter += 1; + state.backup_size += size; + state.backup_stat = state.backup_stat + data.upload_stat; Ok(()) } @@ -435,6 +458,8 @@ impl BackupEnvironment { let mut state = self.state.lock().unwrap(); state.file_counter += 1; + state.backup_size += orig_len as u64; + state.backup_stat.size += blob_len as u64; Ok(()) } @@ -457,9 +482,15 @@ impl BackupEnvironment { state.finished = true; // check manifest - let _manifest = self.datastore.load_manifest(&self.backup_dir) + let mut manifest = self.datastore.load_manifest_json(&self.backup_dir) .map_err(|err| format_err!("unable to load manifest blob - {}", err))?; + let stats = serde_json::to_value(state.backup_stat)?; + + manifest["unprotected"]["chunk_upload_stats"] = stats; + + self.datastore.store_manifest(&self.backup_dir, manifest) + .map_err(|err| format_err!("unable to store manifest blob - {}", err))?; for snap in &state.base_snapshots { let path = self.datastore.snapshot_path(snap);