summaryrefslogtreecommitdiff
path: root/src/backup.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-09-06 10:56:30 +0200
committerfxqnlr <[email protected]>2024-09-06 10:56:30 +0200
commit3e1cb020d5449849b37874f91cadfa4a9c878747 (patch)
treec5503a137c77ac33c1e7ddfd4087cc994b51a43b /src/backup.rs
downloadarbs-3e1cb020d5449849b37874f91cadfa4a9c878747.tar
arbs-3e1cb020d5449849b37874f91cadfa4a9c878747.tar.gz
arbs-3e1cb020d5449849b37874f91cadfa4a9c878747.zip
initial commit, can save index, no modification check
Diffstat (limited to 'src/backup.rs')
-rw-r--r--src/backup.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/backup.rs b/src/backup.rs
new file mode 100644
index 0000000..4e74c97
--- /dev/null
+++ b/src/backup.rs
@@ -0,0 +1,44 @@
1use std::time::{SystemTime, UNIX_EPOCH};
2
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6use crate::{config::Config, pathinfo::PathInfo, packages::Package, error::Result};
7
8pub type BackupId = String;
9
10#[derive(Debug, Serialize, Deserialize)]
11pub struct Backup {
12 id: String,
13 timestamp: u64,
14 packages: Vec<Package>,
15 files: Vec<PathInfo>,
16}
17
18impl Backup {
19 pub fn create(config: &Config, packages: Vec<Package>) -> Result<Self> {
20 let mut files: Vec<PathInfo> = Vec::new();
21 for dir in &config.directories {
22 files.push(PathInfo::from_path(config, dir)?);
23 }
24 Ok(Self {
25 // UUID not really needed, maybe a shorter hash
26 id: Uuid::new_v4().to_string(),
27 timestamp: SystemTime::now()
28 .duration_since(UNIX_EPOCH)
29 .unwrap()
30 .as_secs(),
31 packages,
32 files,
33 })
34 }
35
36
37}
38
39struct BackupLocation {
40 id: BackupId,
41 rel_location: String,
42}
43
44type BackupList = Vec<BackupLocation>;