feat: store end time as metadata
ci/woodpecker/push/lint Pipeline was successful Details
ci/woodpecker/push/clippy Pipeline was successful Details
ci/woodpecker/push/build Pipeline was successful Details

export-backup
Jef Roosens 2023-07-03 12:59:50 +02:00
parent 2c256cf904
commit f71db90922
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 8 additions and 1 deletions

View File

@ -33,6 +33,8 @@ pub enum BackupType {
pub struct Backup<T: Clone> { pub struct Backup<T: Clone> {
/// When the backup was started (also corresponds to the name) /// When the backup was started (also corresponds to the name)
pub start_time: chrono::DateTime<Utc>, pub start_time: chrono::DateTime<Utc>,
/// When the backup finished
pub end_time: chrono::DateTime<Utc>,
pub size: usize, pub size: usize,
/// Type of the backup /// Type of the backup
pub type_: BackupType, pub type_: BackupType,
@ -117,6 +119,7 @@ impl<T: Clone> Backup<T> {
Ok(Backup { Ok(Backup {
type_: BackupType::Full, type_: BackupType::Full,
start_time, start_time,
end_time: chrono::Utc::now(),
size: tar_gz.bytes_written(), size: tar_gz.bytes_written(),
delta, delta,
metadata: None, metadata: None,
@ -174,6 +177,7 @@ impl<T: Clone> Backup<T> {
Ok(Backup { Ok(Backup {
type_: BackupType::Incremental, type_: BackupType::Incremental,
start_time, start_time,
end_time: chrono::Utc::now(),
size: tar_gz.bytes_written(), size: tar_gz.bytes_written(),
delta, delta,
metadata: None, metadata: None,
@ -237,12 +241,15 @@ impl<T: Clone> fmt::Display for Backup<T> {
// life choices // life choices
let index = self.size.ilog(1024) as usize; let index = self.size.ilog(1024) as usize;
let size = self.size as f64 / (1024.0_f64.powi(index as i32)); let size = self.size as f64 / (1024.0_f64.powi(index as i32));
let duration = self.end_time - self.start_time;
write!( write!(
f, f,
"{} ({}, {:.2}{}, {})", "{} ({}, {}m{}s, {:.2}{}, {})",
self.start_time.format(Backup::FILENAME_FORMAT), self.start_time.format(Backup::FILENAME_FORMAT),
letter, letter,
duration.num_seconds() / 60,
duration.num_seconds() % 60,
size, size,
BYTE_SUFFIXES[index], BYTE_SUFFIXES[index],
self.delta self.delta