add backup related types and cmd arguments

- fix some typos & format
This commit is contained in:
qwjyh 2024-03-13 20:09:51 +09:00
parent d1f7a4787e
commit 56563a0e8b
10 changed files with 244 additions and 34 deletions

55
src/backups.rs Normal file
View file

@ -0,0 +1,55 @@
use std::path::PathBuf;
use chrono::{DateTime, Local};
use serde::{Deserialize, Serialize};
use crate::storages::Storage;
/// Targets for backup source or destination.
#[derive(Debug, Serialize, Deserialize)]
pub struct BackupTarget {
storage: Storage,
path: PathBuf,
}
/// Type of backup commands.
#[derive(Debug, Serialize, Deserialize)]
pub enum BackupCommand {
ExternallyInvoked(ExternallyInvoked),
}
/// Backup commands which is not invoked from xdbm itself.
/// Call xdbm externally to record backup datetime and status.
#[derive(Debug, Serialize, Deserialize)]
pub struct ExternallyInvoked {
name: String,
pub note: String,
}
/// Backup execution log.
#[derive(Debug, Serialize, Deserialize)]
pub struct BackupLog {
datetime: DateTime<Local>,
status: BackupResult,
log: String,
}
/// Result of backup.
#[derive(Debug, Serialize, Deserialize)]
pub enum BackupResult {
Success,
Failure,
}
/// Backup source, destination, command and logs.
#[derive(Debug, Serialize, Deserialize)]
pub struct Backup {
/// must be unique
name: String,
/// name of [`crate::Device`]
device: String,
from: BackupTarget,
to: BackupTarget,
command: BackupCommand,
logs: Vec<BackupLog>,
}