Skip to main content

orca_core/backup/
config.rs

1use serde::{Deserialize, Serialize};
2
3/// Configuration for the backup system.
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct BackupConfig {
6    /// Cron expression for scheduled backups (e.g. "0 0 2 * * *" for 2am daily).
7    #[serde(default)]
8    pub schedule: Option<String>,
9
10    /// Number of days to retain backups before pruning.
11    #[serde(default = "default_retention_days")]
12    pub retention_days: u32,
13
14    /// Where to store backups.
15    #[serde(default)]
16    pub targets: Vec<BackupTarget>,
17}
18
19fn default_retention_days() -> u32 {
20    30
21}
22
23/// A backup storage destination.
24#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(tag = "type", rename_all = "lowercase")]
26pub enum BackupTarget {
27    Local {
28        path: String,
29    },
30    S3 {
31        bucket: String,
32        region: String,
33        #[serde(default)]
34        prefix: Option<String>,
35        /// Optional S3-compatible endpoint (for Minio, R2, B2, etc.).
36        #[serde(default)]
37        endpoint: Option<String>,
38        /// AWS access key. Falls back to `AWS_ACCESS_KEY_ID` env var.
39        #[serde(default)]
40        access_key: Option<String>,
41        /// AWS secret key. Falls back to `AWS_SECRET_ACCESS_KEY` env var.
42        #[serde(default)]
43        secret_key: Option<String>,
44    },
45}
46
47/// Per-service backup settings.
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct ServiceBackupConfig {
50    /// Whether backups are enabled for this service.
51    #[serde(default)]
52    pub enabled: bool,
53
54    /// Command to run before backup (e.g. "pg_dump -U postgres mydb > /tmp/dump.sql").
55    #[serde(default)]
56    pub pre_hook: Option<String>,
57}
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn parse_backup_config() {
65        let toml = r#"
66schedule = "0 0 2 * * *"
67retention_days = 7
68
69[[targets]]
70type = "local"
71path = "/backups"
72
73[[targets]]
74type = "s3"
75bucket = "my-backups"
76region = "eu-central-1"
77prefix = "orca/"
78"#;
79        let config: BackupConfig = toml::from_str(toml).unwrap();
80        assert_eq!(config.retention_days, 7);
81        assert_eq!(config.targets.len(), 2);
82    }
83}