Files
tessera/crates/tessera-core/src/manifest.rs
Adnan Zahir b104aa8053 fix: restore safety copies no longer compete with production captures in retention
A safety copy of a restore target was stored in the application's orbit and weighed by the same
retention as captures, so the newest copy (the target's) could push the production capture that had
just been restored out of the keep set, whatever the rule (GFS, count or age). Safety copies are now
separated: they have their own per-target rule (newest three plus anything under seven days) and
never count for or against captures. Proven red on the old behaviour with a real refresh.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 12:35:28 +07:00

59 lines
1.8 KiB
Rust

use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SnapshotManifest {
pub snapshot_id: Uuid,
pub orbit_id: Uuid,
pub orbit_name: String,
pub labels: Vec<String>,
pub provider: String,
pub paths: Vec<String>,
pub restore_hints: serde_json::Value,
}
impl SnapshotManifest {
/// A copy of a restore target's database taken before it was overwritten. It belongs to the target, not
/// to the application's backup history: retention must never weigh it against real captures.
pub fn is_restore_safety(&self) -> bool {
self.labels.iter().any(|label| label == "restore-safety")
|| self.restore_hints.get("safety_for").is_some()
}
/// The restore target a safety copy was taken from.
pub fn safety_target(&self) -> Option<String> {
self.restore_hints
.get("target_id")
.and_then(|id| id.as_str())
.map(str::to_string)
}
}
pub fn manifest_hash(manifest: &SnapshotManifest) -> String {
let json = serde_json::to_vec(manifest).expect("manifest serializes");
let digest = Sha256::digest(&json);
hex::encode(digest)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hash_is_stable() {
let m = SnapshotManifest {
snapshot_id: Uuid::nil(),
orbit_id: Uuid::nil(),
orbit_name: "nightly".into(),
labels: vec!["filesystem".into()],
provider: "filesystem".into(),
paths: vec!["/tmp".into()],
restore_hints: serde_json::json!({}),
};
let h1 = manifest_hash(&m);
let h2 = manifest_hash(&m);
assert_eq!(h1, h2);
assert_eq!(h1.len(), 64);
}
}