feat: add managed database capture and operator restore

PostgreSQL and MySQL backups run through paired outposts, with operator sign-in, off-site copies, and legacy import. Retention stays on each orbit, so the unused retention console is removed.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-10 23:26:49 +07:00
parent 30a1a9b8f0
commit 6320b6f244
96 changed files with 11061 additions and 725 deletions

View File

@@ -58,6 +58,47 @@ impl RetentionPolicy {
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(tag = "mode", rename_all = "snake_case", deny_unknown_fields)]
pub enum CaptureRetention {
Age { days: u16 },
Count { #[serde(default = "fallback_count")] keep: u16 },
}
fn fallback_count() -> u16 {
5
}
impl Default for CaptureRetention {
fn default() -> Self {
Self::Age { days: 14 }
}
}
impl CaptureRetention {
pub fn is_valid(self) -> bool {
match self {
Self::Age { days } => days > 0,
Self::Count { keep } => keep > 0,
}
}
}
pub fn evaluate_capture_retention(
policy: CaptureRetention,
mut snapshots: Vec<SnapshotRef>,
now: DateTime<Utc>,
) -> Vec<Uuid> {
snapshots.sort_unstable_by_key(|snapshot| std::cmp::Reverse((snapshot.taken_at, snapshot.id)));
snapshots.into_iter().enumerate().skip(1).filter_map(|(index, snapshot)| {
let expired = match policy {
CaptureRetention::Age { days } => now.signed_duration_since(snapshot.taken_at).num_days() >= i64::from(days),
CaptureRetention::Count { keep } => index >= usize::from(keep),
};
expired.then_some(snapshot.id)
}).collect()
}
/// Keep the newest snapshot in each of the most recent occupied UTC periods.
pub fn evaluate_gfs(policy: &RetentionPolicy, mut snapshots: Vec<SnapshotRef>) -> Vec<Uuid> {
if !policy.has_tiers() {
@@ -160,6 +201,19 @@ mod tests {
use super::*;
use chrono::{Duration, TimeZone, Timelike};
#[test]
fn capture_retention_keeps_one_old_archive_or_the_latest_five() {
let now = Utc::now();
let snapshots: Vec<_> = (0..6).map(|i| SnapshotRef {
id: Uuid::new_v4(),
taken_at: now - Duration::days(15 + i),
}).collect();
assert_eq!(evaluate_capture_retention(CaptureRetention::default(), snapshots.clone(), now),
snapshots[1..].iter().map(|snap| snap.id).collect::<Vec<_>>());
assert_eq!(evaluate_capture_retention(CaptureRetention::Count { keep: 5 }, snapshots.clone(), now),
[snapshots[5].id]);
}
#[test]
fn gfs_keeps_the_newest_in_each_period_and_combines_tiers() {
let policy = RetentionPolicy {