]> git.proxmox.com Git - proxmox-backup.git/blobdiff - src/api2/admin/datastore/catar.rs
src/catar/decoder.rs: simplify public restore API
[proxmox-backup.git] / src / api2 / admin / datastore / catar.rs
index c377174ec1faae6f01a635158d803b966bc47570..6e8e4b7d715a87eba68e85341e48db5588771302 100644 (file)
@@ -12,7 +12,7 @@ use chrono::{Local, TimeZone};
 use serde_json::Value;
 use std::io::Write;
 use futures::*;
-use std::path::PathBuf;
+//use std::path::PathBuf;
 use std::sync::Arc;
 
 use hyper::Body;
@@ -63,9 +63,9 @@ fn upload_catar(
 
     archive_name.push_str(".didx");
 
-    let backup_type = tools::required_string_param(&param, "type")?;
-    let backup_id = tools::required_string_param(&param, "id")?;
-    let backup_time = tools::required_integer_param(&param, "time")?;
+    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")?;
 
     println!("Upload {}/{}/{}/{}/{}", store, backup_type, backup_id, backup_time, archive_name);
 
@@ -80,9 +80,9 @@ fn upload_catar(
     verify_chunk_size(chunk_size)?;
 
     let datastore = DataStore::lookup_datastore(store)?;
+    let backup_dir = BackupDir::new(backup_type, backup_id, backup_time);
 
-    let (mut path, _new) = datastore.create_backup_dir(
-        backup_type, backup_id, Local.timestamp(backup_time, 0))?;
+    let (mut path, _new) = datastore.create_backup_dir(&backup_dir)?;
 
     path.push(archive_name);
 
@@ -109,10 +109,10 @@ pub fn api_method_upload_catar() -> ApiAsyncMethod {
         ObjectSchema::new("Upload .catar backup file.")
             .required("store", StringSchema::new("Datastore name."))
             .required("archive-name", StringSchema::new("Backup archive name."))
-            .required("type", StringSchema::new("Backup type.")
+            .required("backup-type", StringSchema::new("Backup type.")
                       .format(Arc::new(ApiStringFormat::Enum(vec!["ct".into(), "host".into()]))))
-            .required("id", StringSchema::new("Backup ID."))
-            .required("time", IntegerSchema::new("Backup time (Unix epoch.)")
+            .required("backup-id", StringSchema::new("Backup ID."))
+            .required("backup-time", IntegerSchema::new("Backup time (Unix epoch.)")
                       .minimum(1547797308))
             .optional(
                 "chunk-size",
@@ -133,32 +133,27 @@ fn download_catar(
 ) -> Result<BoxFut, Error> {
 
     let store = tools::required_string_param(&param, "store")?;
-    let archive_name = tools::required_string_param(&param, "archive-name")?;
+    let mut archive_name = tools::required_string_param(&param, "archive-name")?.to_owned();
 
-    let backup_type = tools::required_string_param(&param, "type")?;
-    let backup_id = tools::required_string_param(&param, "id")?;
-    let backup_time = tools::required_integer_param(&param, "time")?;
-    let backup_time = Local.timestamp(backup_time, 0);
+    if !archive_name.ends_with(".catar") {
+        bail!("wrong archive extension");
+    } else {
+        archive_name.push_str(".didx");
+    }
+
+    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")?;
 
-    println!("Download {}.catar from {} ({}/{}/{}/{}.didx)", archive_name, store,
-             backup_type, backup_id, backup_time, archive_name);
+    println!("Download {} from {} ({}/{}/{}/{})", archive_name, store,
+             backup_type, backup_id, Local.timestamp(backup_time, 0), archive_name);
 
     let datastore = DataStore::lookup_datastore(store)?;
 
-    let backup_dir = BackupDir {
-        group: BackupGroup {
-            backup_type: backup_type.to_string(),
-            backup_id: backup_id.to_string(),
-        },
-        backup_time,
-    };
+    let backup_dir = BackupDir::new(backup_type, backup_id, backup_time);
 
     let mut path = backup_dir.relative_path();
-
-    let mut full_archive_name = PathBuf::from(archive_name);
-    full_archive_name.set_extension("didx");
-
-    path.push(full_archive_name);
+    path.push(archive_name);
 
     let index = datastore.open_dynamic_reader(path)?;
     let reader = BufferedDynamicReader::new(index);
@@ -178,10 +173,10 @@ pub fn api_method_download_catar() -> ApiAsyncMethod {
         ObjectSchema::new("Download .catar backup file.")
             .required("store", StringSchema::new("Datastore name."))
             .required("archive-name", StringSchema::new("Backup archive name."))
-            .required("type", StringSchema::new("Backup type.")
+            .required("backup-type", StringSchema::new("Backup type.")
                       .format(Arc::new(ApiStringFormat::Enum(vec!["ct".into(), "host".into()]))))
-            .required("id", StringSchema::new("Backup ID."))
-            .required("time", IntegerSchema::new("Backup time (Unix epoch.)")
+            .required("backup-id", StringSchema::new("Backup ID."))
+            .required("backup-time", IntegerSchema::new("Backup time (Unix epoch.)")
                       .minimum(1547797308))
 
     )