fraiseql_server/backup/
clickhouse_backup.rs1use std::collections::HashMap;
4
5use super::backup_provider::{BackupError, BackupInfo, BackupProvider, BackupResult, StorageUsage};
6
7#[allow(dead_code)]
11pub struct ClickhouseBackupProvider {
12 endpoint_url: String,
14 backup_dir: String,
16}
17
18impl ClickhouseBackupProvider {
19 pub fn new(endpoint_url: String, backup_dir: String) -> Self {
21 Self {
22 endpoint_url,
23 backup_dir,
24 }
25 }
26
27 fn generate_backup_id() -> String {
28 let timestamp = std::time::SystemTime::now()
29 .duration_since(std::time::UNIX_EPOCH)
30 .map(|d| d.as_secs())
31 .unwrap_or(0);
32 format!("clickhouse-{}", timestamp)
33 }
34}
35
36#[async_trait::async_trait]
37impl BackupProvider for ClickhouseBackupProvider {
38 fn name(&self) -> &'static str {
39 "clickhouse"
40 }
41
42 async fn health_check(&self) -> BackupResult<()> {
43 Ok(())
45 }
46
47 async fn backup(&self) -> BackupResult<BackupInfo> {
48 let backup_id = Self::generate_backup_id();
49
50 Ok(BackupInfo {
57 backup_id,
58 store_name: "clickhouse".to_string(),
59 timestamp: std::time::SystemTime::now()
60 .duration_since(std::time::UNIX_EPOCH)
61 .map(|d| d.as_secs() as i64)
62 .unwrap_or(0),
63 size_bytes: 0,
64 verified: false,
65 compression: None, metadata: {
67 let mut m = HashMap::new();
68 m.insert("method".to_string(), "native_snapshot".to_string());
69 m.insert("partitioned".to_string(), "true".to_string());
70 m
71 },
72 })
73 }
74
75 async fn restore(&self, backup_id: &str, verify: bool) -> BackupResult<()> {
76 if verify {
81 self.verify_backup(backup_id).await?;
82 }
83 Ok(())
84 }
85
86 async fn list_backups(&self) -> BackupResult<Vec<BackupInfo>> {
87 Ok(Vec::new())
88 }
89
90 async fn get_backup(&self, backup_id: &str) -> BackupResult<BackupInfo> {
91 Err(BackupError::NotFound {
92 store: "clickhouse".to_string(),
93 backup_id: backup_id.to_string(),
94 })
95 }
96
97 async fn delete_backup(&self, _backup_id: &str) -> BackupResult<()> {
98 Ok(())
99 }
100
101 async fn verify_backup(&self, _backup_id: &str) -> BackupResult<()> {
102 Ok(())
104 }
105
106 async fn get_storage_usage(&self) -> BackupResult<StorageUsage> {
107 Ok(StorageUsage {
108 total_bytes: 0,
109 backup_count: 0,
110 oldest_backup_timestamp: None,
111 newest_backup_timestamp: None,
112 })
113 }
114}
115
116#[cfg(test)]
117mod tests {
118 use super::*;
119
120 #[tokio::test]
121 async fn test_clickhouse_backup() {
122 let provider =
123 ClickhouseBackupProvider::new("http://localhost:8123".to_string(), "/tmp".to_string());
124 let backup = provider.backup().await.unwrap();
125 assert_eq!(backup.store_name, "clickhouse");
126 }
127}