SnapshotVerifyState: use enum for state
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
parent
43772efc6e
commit
d10332a15d
|
@ -120,11 +120,9 @@ async move {
|
||||||
let verify = manifest.unprotected["verify_state"].clone();
|
let verify = manifest.unprotected["verify_state"].clone();
|
||||||
match serde_json::from_value::<SnapshotVerifyState>(verify) {
|
match serde_json::from_value::<SnapshotVerifyState>(verify) {
|
||||||
Ok(verify) => {
|
Ok(verify) => {
|
||||||
if verify.state != "ok" {
|
match verify.state {
|
||||||
// verify failed, treat as if no previous backup exists
|
VerifyState::Ok => Some(info),
|
||||||
None
|
VerifyState::Failed => None,
|
||||||
} else {
|
|
||||||
Some(info)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
|
|
@ -9,7 +9,7 @@ use proxmox::tools::digest_to_hex;
|
||||||
use proxmox::tools::fs::{replace_file, CreateOptions};
|
use proxmox::tools::fs::{replace_file, CreateOptions};
|
||||||
use proxmox::api::{RpcEnvironment, RpcEnvironmentType};
|
use proxmox::api::{RpcEnvironment, RpcEnvironmentType};
|
||||||
|
|
||||||
use crate::api2::types::{Userid, SnapshotVerifyState};
|
use crate::api2::types::{Userid, SnapshotVerifyState, VerifyState};
|
||||||
use crate::backup::*;
|
use crate::backup::*;
|
||||||
use crate::server::WorkerTask;
|
use crate::server::WorkerTask;
|
||||||
use crate::server::formatter::*;
|
use crate::server::formatter::*;
|
||||||
|
@ -466,7 +466,7 @@ impl BackupEnvironment {
|
||||||
let mark_msg = if let Some(ref last_backup) = self.last_backup {
|
let mark_msg = if let Some(ref last_backup) = self.last_backup {
|
||||||
let last_dir = &last_backup.backup_dir;
|
let last_dir = &last_backup.backup_dir;
|
||||||
let verify_state = SnapshotVerifyState {
|
let verify_state = SnapshotVerifyState {
|
||||||
state: "failed".to_owned(),
|
state: VerifyState::Failed,
|
||||||
upid: self.worker.upid().clone(),
|
upid: self.worker.upid().clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -380,13 +380,24 @@ pub struct GroupListItem {
|
||||||
pub owner: Option<Userid>,
|
pub owner: Option<Userid>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[api()]
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
/// Result of a verify operation.
|
||||||
|
pub enum VerifyState {
|
||||||
|
/// Verification was successful
|
||||||
|
Ok,
|
||||||
|
/// Verification reported one or more errors
|
||||||
|
Failed,
|
||||||
|
}
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
properties: {
|
properties: {
|
||||||
upid: {
|
upid: {
|
||||||
schema: UPID_SCHEMA
|
schema: UPID_SCHEMA
|
||||||
},
|
},
|
||||||
state: {
|
state: {
|
||||||
type: String
|
type: VerifyState
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
|
@ -395,8 +406,8 @@ pub struct GroupListItem {
|
||||||
pub struct SnapshotVerifyState {
|
pub struct SnapshotVerifyState {
|
||||||
/// UPID of the verify task
|
/// UPID of the verify task
|
||||||
pub upid: UPID,
|
pub upid: UPID,
|
||||||
/// State of the verification. "failed" or "ok"
|
/// State of the verification. Enum.
|
||||||
pub state: String,
|
pub state: VerifyState,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
|
|
|
@ -283,7 +283,7 @@ pub fn verify_backup_dir(
|
||||||
|
|
||||||
let mut error_count = 0;
|
let mut error_count = 0;
|
||||||
|
|
||||||
let mut verify_result = "ok";
|
let mut verify_result = VerifyState::Ok;
|
||||||
for info in manifest.files() {
|
for info in manifest.files() {
|
||||||
let result = proxmox::try_block!({
|
let result = proxmox::try_block!({
|
||||||
worker.log(format!(" check {}", info.filename));
|
worker.log(format!(" check {}", info.filename));
|
||||||
|
@ -316,20 +316,19 @@ pub fn verify_backup_dir(
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
worker.log(format!("verify {}:{}/{} failed: {}", datastore.name(), backup_dir, info.filename, err));
|
worker.log(format!("verify {}:{}/{} failed: {}", datastore.name(), backup_dir, info.filename, err));
|
||||||
error_count += 1;
|
error_count += 1;
|
||||||
verify_result = "failed";
|
verify_result = VerifyState::Failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let verify_state = SnapshotVerifyState {
|
let verify_state = SnapshotVerifyState {
|
||||||
state: verify_result.to_string(),
|
state: verify_result,
|
||||||
upid: worker.upid().clone(),
|
upid: worker.upid().clone(),
|
||||||
};
|
};
|
||||||
manifest.unprotected["verify_state"] = serde_json::to_value(verify_state)?;
|
manifest.unprotected["verify_state"] = serde_json::to_value(verify_state)?;
|
||||||
datastore.store_manifest(&backup_dir, serde_json::to_value(manifest)?)
|
datastore.store_manifest(&backup_dir, serde_json::to_value(manifest)?)
|
||||||
.map_err(|err| format_err!("unable to store manifest blob - {}", err))?;
|
.map_err(|err| format_err!("unable to store manifest blob - {}", err))?;
|
||||||
|
|
||||||
|
|
||||||
Ok(error_count == 0)
|
Ok(error_count == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue