src/backup/datastore.rs: use unix epoch to create DateTime

To make sure that we have a timestamp without nanosecond.
This commit is contained in:
Dietmar Maurer 2019-03-04 17:58:22 +01:00
parent 38f8815925
commit 875fb1c01a
4 changed files with 11 additions and 14 deletions

View File

@ -6,7 +6,7 @@ use crate::api_schema::router::*;
//use crate::server::rest::*;
use serde_json::{json, Value};
use std::collections::{HashSet, HashMap};
use chrono::{DateTime, Datelike, Local, TimeZone};
use chrono::{DateTime, Datelike, Local};
use std::path::PathBuf;
use std::sync::Arc;
@ -97,7 +97,6 @@ fn delete_snapshots (
let backup_type = tools::required_string_param(&param, "backup-type")?;
let backup_id = tools::required_string_param(&param, "backup-id")?;
let backup_time = tools::required_integer_param(&param, "backup-time")?;
let backup_time = Local.timestamp(backup_time, 0);
let snapshot = BackupDir::new(BackupGroup::new(backup_type, backup_id), backup_time);

View File

@ -138,10 +138,9 @@ fn download_catar(
let backup_type = tools::required_string_param(&param, "backup-type")?;
let backup_id = tools::required_string_param(&param, "backup-id")?;
let backup_time = tools::required_integer_param(&param, "backup-time")?;
let backup_time = Local.timestamp(backup_time, 0);
println!("Download {}.catar from {} ({}/{}/{}/{}.didx)", archive_name, store,
backup_type, backup_id, backup_time, archive_name);
backup_type, backup_id, Local.timestamp(backup_time, 0), archive_name);
let datastore = DataStore::lookup_datastore(store)?;

View File

@ -84,8 +84,9 @@ pub struct BackupDir {
impl BackupDir {
pub fn new(group: BackupGroup, backup_time: DateTime<Local>) -> Self {
Self { group, backup_time }
pub fn new(group: BackupGroup, timestamp: i64) -> Self {
// Note: makes sure that nanoseconds is 0
Self { group, backup_time: Local.timestamp(timestamp, 0) }
}
pub fn group(&self) -> &BackupGroup {
@ -103,7 +104,7 @@ impl BackupDir {
let group = BackupGroup::new(cap.get(1).unwrap().as_str(), cap.get(2).unwrap().as_str());
let backup_time = cap.get(3).unwrap().as_str().parse::<DateTime<Local>>()?;
Ok(BackupDir::new(group, backup_time))
Ok(BackupDir::new(group, backup_time.timestamp()))
}
fn backup_time_to_file_name(backup_time: DateTime<Local>) -> String {
@ -332,7 +333,7 @@ impl DataStore {
})?;
list.push(BackupInfo {
backup_dir: BackupDir::new(BackupGroup::new(backup_type, backup_id), dt),
backup_dir: BackupDir::new(BackupGroup::new(backup_type, backup_id), dt.timestamp()),
files,
});

View File

@ -110,9 +110,8 @@ fn list_backups(
let id = item["backup-id"].as_str().unwrap();
let btype = item["backup-type"].as_str().unwrap();
let epoch = item["backup-time"].as_i64().unwrap();
let backup_time = Local.timestamp(epoch, 0);
let backup_dir = BackupDir::new(BackupGroup::new(btype, id), backup_time);
let backup_dir = BackupDir::new(BackupGroup::new(btype, id), epoch);
let files = item["files"].as_array().unwrap().iter().map(|v| v.as_str().unwrap().to_owned()).collect();
@ -120,7 +119,7 @@ fn list_backups(
for filename in info.files {
let path = info.backup_dir.relative_path().to_str().unwrap().to_owned();
println!("{} | {}/{}", backup_time.format("%c"), path, filename);
println!("{} | {}/{}", info.backup_dir.backup_time().format("%c"), path, filename);
}
}
@ -203,9 +202,8 @@ fn list_snapshots(
let id = item["backup-id"].as_str().unwrap();
let btype = item["backup-type"].as_str().unwrap();
let epoch = item["backup-time"].as_i64().unwrap();
let backup_time = Local.timestamp(epoch, 0);
let snapshot = BackupDir::new(BackupGroup::new(btype, id), backup_time);
let snapshot = BackupDir::new(BackupGroup::new(btype, id), epoch);
let path = snapshot.relative_path().to_str().unwrap().to_owned();
@ -214,7 +212,7 @@ fn list_snapshots(
v.as_str().unwrap().to_owned()
}).collect();
println!("{} | {} | {}", path, backup_time.format("%c"), tools::join(&files, ' '));
println!("{} | {} | {}", path, snapshot.backup_time().format("%c"), tools::join(&files, ' '));
}
Ok(Value::Null)