mirror of
https://github.com/qwjyh/xdbm
synced 2025-07-17 03:59:19 +09:00
add backup done
This commit is contained in:
parent
4f0d725b52
commit
b1b174b4b3
7 changed files with 117 additions and 12 deletions
|
@ -101,11 +101,23 @@ impl BackupCommandExt for ExternallyInvoked {
|
|||
/// Backup execution log.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct BackupLog {
|
||||
datetime: DateTime<Local>,
|
||||
pub datetime: DateTime<Local>,
|
||||
status: BackupResult,
|
||||
log: String,
|
||||
}
|
||||
|
||||
impl BackupLog {
|
||||
pub fn new_with_current_time(status: BackupResult, log: String) -> BackupLog {
|
||||
let timestamp = Local::now();
|
||||
trace!("Generating timestamp: {:?}", timestamp);
|
||||
BackupLog {
|
||||
datetime: timestamp,
|
||||
status,
|
||||
log,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Result of backup.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum BackupResult {
|
||||
|
@ -113,6 +125,16 @@ pub enum BackupResult {
|
|||
Failure,
|
||||
}
|
||||
|
||||
impl BackupResult {
|
||||
pub fn from_exit_code(code: u64) -> Self {
|
||||
if code == 0 {
|
||||
Self::Success
|
||||
} else {
|
||||
Self::Failure
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Backup source, destination, command and logs.
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Backup {
|
||||
|
@ -164,6 +186,15 @@ impl Backup {
|
|||
pub fn command(&self) -> &BackupCommand {
|
||||
&self.command
|
||||
}
|
||||
|
||||
pub fn add_log(&mut self, newlog: BackupLog) -> () {
|
||||
self.logs.push(newlog)
|
||||
}
|
||||
|
||||
/// Get the last backup.
|
||||
pub fn last_backup(&self) -> Option<&BackupLog> {
|
||||
self.logs.iter().max_by_key(|log| log.datetime)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
@ -183,6 +214,10 @@ impl Backups {
|
|||
self.list.get(name)
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, name: &String) -> Option<&mut Backup> {
|
||||
self.list.get_mut(name)
|
||||
}
|
||||
|
||||
/// Add new [`Backup`].
|
||||
/// New `backup` must has new unique name.
|
||||
pub fn add(&mut self, backup: Backup) -> Result<()> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue