diff --git a/src/api3/admin/datastore/catar.rs b/src/api3/admin/datastore/catar.rs index 52529dc3..d5e0da67 100644 --- a/src/api3/admin/datastore/catar.rs +++ b/src/api3/admin/datastore/catar.rs @@ -74,7 +74,7 @@ fn upload_catar(parts: Parts, req_body: Body, param: Value, _info: &ApiAsyncMeth path.push(full_archive_name); - let index = datastore.create_archive_writer(path, chunk_size).unwrap(); + let index = datastore.create_archive_writer(path, chunk_size)?; let upload = UploadCaTar { stream: req_body, index, count: 0}; @@ -108,6 +108,27 @@ pub fn api_method_upload_catar() -> ApiAsyncMethod { fn download_catar(parts: Parts, req_body: Body, param: Value, _info: &ApiAsyncMethod) -> Result { + let store = tools::required_string_param(¶m, "store")?; + let archive_name = tools::required_string_param(¶m, "archive_name")?; + + let backup_type = tools::required_string_param(¶m, "type")?; + let backup_id = tools::required_string_param(¶m, "id")?; + let backup_time = tools::required_integer_param(¶m, "time")?; + + println!("Download {}.catar from {} ({}/{}/{}/{}.aidx)", archive_name, store, + backup_type, backup_id, backup_time, archive_name); + + let datastore = DataStore::lookup_datastore(store)?; + + let mut path = datastore.get_backup_dir(backup_type, backup_id, backup_time); + + let mut full_archive_name = PathBuf::from(archive_name); + full_archive_name.set_extension("aidx"); + + path.push(full_archive_name); + + let index = datastore.open_archive_reader(path)?; + bail!("not implemeneted"); } diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 7ba912ba..43fb2750 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -101,6 +101,27 @@ impl DataStore { self.chunk_store.base_path() } + pub fn get_backup_dir( + &self, + backup_type: &str, + backup_id: &str, + backup_time: i64, + ) -> PathBuf { + + let mut relative_path = PathBuf::new(); + + relative_path.push(backup_type); + + relative_path.push(backup_id); + + let dt = Utc.timestamp(backup_time, 0); + let date_str = dt.format("%Y-%m-%dT%H:%M:%S").to_string(); + + relative_path.push(&date_str); + + relative_path + } + pub fn create_backup_dir( &self, backup_type: &str,