diff options
Diffstat (limited to 'src/backup.rs')
-rw-r--r-- | src/backup.rs | 44 |
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 @@ | |||
1 | use std::time::{SystemTime, UNIX_EPOCH}; | ||
2 | |||
3 | use serde::{Deserialize, Serialize}; | ||
4 | use uuid::Uuid; | ||
5 | |||
6 | use crate::{config::Config, pathinfo::PathInfo, packages::Package, error::Result}; | ||
7 | |||
8 | pub type BackupId = String; | ||
9 | |||
10 | #[derive(Debug, Serialize, Deserialize)] | ||
11 | pub struct Backup { | ||
12 | id: String, | ||
13 | timestamp: u64, | ||
14 | packages: Vec<Package>, | ||
15 | files: Vec<PathInfo>, | ||
16 | } | ||
17 | |||
18 | impl 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 | |||
39 | struct BackupLocation { | ||
40 | id: BackupId, | ||
41 | rel_location: String, | ||
42 | } | ||
43 | |||
44 | type BackupList = Vec<BackupLocation>; | ||