diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index 1a50634e..1c0b0a8a 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -81,6 +81,7 @@ fn get_backup_list( "backup_type": info.backup_type, "backup_id": info.backup_id, "backup_time": info.backup_time.timestamp(), + "files": info.files, })); } diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index eee71657..d52397fd 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -33,6 +33,8 @@ pub struct BackupInfo { pub backup_id: String, /// Backup timestamp pub backup_time: DateTime, + /// List of data files + pub files: Vec, } lazy_static!{ @@ -172,6 +174,7 @@ impl DataStore { let mut list = vec![]; lazy_static! { + static ref BACKUP_FILE_REGEX: regex::Regex = regex::Regex::new(r"^.*\.([fd]idx)$").unwrap(); static ref BACKUP_TYPE_REGEX: regex::Regex = regex::Regex::new(r"^(host|vm|ct)$").unwrap(); static ref BACKUP_ID_REGEX: regex::Regex = regex::Regex::new(r"^[A-Za-z][A-Za-z0-9_-]+$").unwrap(); static ref BACKUP_DATE_REGEX: regex::Regex = regex::Regex::new( @@ -182,15 +185,24 @@ impl DataStore { if file_type != nix::dir::Type::Directory { return Ok(()); } tools::scandir(l0_fd, backup_type, &BACKUP_ID_REGEX, |l1_fd, backup_id, file_type| { if file_type != nix::dir::Type::Directory { return Ok(()); } - tools::scandir(l1_fd, backup_id, &BACKUP_DATE_REGEX, |_, backup_time, file_type| { + tools::scandir(l1_fd, backup_id, &BACKUP_DATE_REGEX, |l2_fd, backup_time, file_type| { if file_type != nix::dir::Type::Directory { return Ok(()); } let dt = Utc.datetime_from_str(backup_time, "%Y-%m-%dT%H:%M:%S")?; + let mut files = vec![]; + + tools::scandir(l2_fd, backup_time, &BACKUP_FILE_REGEX, |_, filename, file_type| { + if file_type != nix::dir::Type::File { return Ok(()); } + files.push(filename.to_owned()); + Ok(()) + })?; + list.push(BackupInfo { backup_type: backup_type.to_owned(), backup_id: backup_id.to_owned(), backup_time: dt, + files, }); Ok(()) diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index 32bb42a4..4eccbc63 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -2,6 +2,7 @@ extern crate proxmox_backup; use failure::*; //use std::os::unix::io::AsRawFd; +use chrono::{Local, TimeZone}; use proxmox_backup::tools; use proxmox_backup::cli::command::*; @@ -92,7 +93,27 @@ fn list_backups( let result = client.get(&path)?; - Ok(result) + // fixme: implement and use output formatter instead .. + let list = result["data"].as_array().unwrap(); + + for item in list { + + 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 time_str = Local.timestamp(epoch, 0).format("%c"); + + let files = item["files"].as_array().unwrap(); + + for file in files { + let filename = file.as_str().unwrap(); + println!("| {} | {} | {} | {}", btype, id, time_str, filename); + } + } + + //Ok(result) + Ok(Value::Null) }