src/backup/datastore.rs: list_backups() - include list of index files
This commit is contained in:
		| @ -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, | ||||
|         })); | ||||
|     } | ||||
|  | ||||
|  | ||||
| @ -33,6 +33,8 @@ pub struct BackupInfo { | ||||
|     pub backup_id: String, | ||||
|     /// Backup timestamp | ||||
|     pub backup_time: DateTime<Utc>, | ||||
|     /// List of data files | ||||
|     pub files: Vec<String>, | ||||
| } | ||||
|  | ||||
| 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(()) | ||||
|  | ||||
| @ -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) | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user