extern crate proxmox_backup;
use failure::*;
-use std::os::unix::io::AsRawFd;
+//use std::os::unix::io::AsRawFd;
use proxmox_backup::tools;
use proxmox_backup::cli::command::*;
//use proxmox_backup::backup::image_index::*;
//use proxmox_backup::config::datastore;
//use proxmox_backup::catar::encoder::*;
-use proxmox_backup::backup::datastore::*;
+//use proxmox_backup::backup::datastore::*;
use serde_json::{Value};
use hyper::Body;
.append_pair("time", &epoch.to_string())
.finish();
- let path = format!("api3/json/admin/datastore/{}/upload_catar?{}", store, query);
+ let path = format!("api2/json/admin/datastore/{}/catar?{}", store, query);
client.upload("application/x-proxmox-backup-catar", body, &path)?;
let mut target = PathBuf::from(target);
if let Some(ext) = target.extension() {
- if ext != "iidx" {
- bail!("got wrong file extension - expected '.iidx'");
+ if ext != "fidx" {
+ bail!("got wrong file extension - expected '.fidx'");
}
} else {
- target.set_extension("iidx");
+ target.set_extension("fidx");
}
let mut index = datastore.create_image_writer(&target, size, chunk_size)?;
}
*/
-fn create_backup(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
+fn list_backups(
+ param: Value,
+ _info: &ApiMethod,
+ _rpcenv: &mut RpcEnvironment,
+) -> Result<Value, Error> {
+
+ let store = tools::required_string_param(¶m, "store")?;
+
+ let client = HttpClient::new("localhost");
+
+ let path = format!("api2/json/admin/datastore/{}/backups", store);
+
+ let result = client.get(&path)?;
+
+ Ok(result)
+}
+
+fn create_backup(
+ param: Value,
+ _info: &ApiMethod,
+ _rpcenv: &mut RpcEnvironment,
+) -> Result<Value, Error> {
let filename = tools::required_string_param(¶m, "filename")?;
let store = tools::required_string_param(¶m, "store")?;
let target = tools::required_string_param(¶m, "target")?;
- let mut chunk_size = 4*1024*1024;
+ let mut _chunk_size = 4*1024*1024;
if let Some(size) = param["chunk-size"].as_u64() {
static SIZES: [u64; 7] = [64, 128, 256, 512, 1024, 2048, 4096];
if SIZES.contains(&size) {
- chunk_size = (size as usize) * 1024;
+ _chunk_size = (size as usize) * 1024;
} else {
bail!("Got unsupported chunk size '{}'", size);
}
println!("Backup image '{}' to '{}'", filename, store);
if stat.st_size <= 0 { bail!("got strange file size '{}'", stat.st_size); }
- let size = stat.st_size as usize;
+ let _size = stat.st_size as usize;
panic!("implement me");
Ok(Value::Null)
}
-
-pub fn complete_file_name(arg: &str) -> Vec<String> {
-
- let mut result = vec![];
-
- use nix::fcntl::OFlag;
- use nix::sys::stat::Mode;
- use nix::fcntl::AtFlags;
-
- let mut dirname = std::path::PathBuf::from(arg);
-
- let is_dir = match nix::sys::stat::fstatat(libc::AT_FDCWD, &dirname, AtFlags::empty()) {
- Ok(stat) => (stat.st_mode & libc::S_IFMT) == libc::S_IFDIR,
- Err(_) => false,
- };
-
- if !is_dir {
- if let Some(parent) = dirname.parent() {
- dirname = parent.to_owned();
- }
- }
-
- let mut dir = match nix::dir::Dir::openat(libc::AT_FDCWD, &dirname, OFlag::O_DIRECTORY, Mode::empty()) {
- Ok(d) => d,
- Err(err) => {
- return result;
- }
- };
-
- for item in dir.iter() {
- if let Ok(entry) = item {
- if let Ok(name) = entry.file_name().to_str() {
- if name == "." || name == ".." { continue; }
- let mut newpath = dirname.clone();
- newpath.push(name);
-
- if let Ok(stat) = nix::sys::stat::fstatat(libc::AT_FDCWD, &newpath, AtFlags::empty()) {
- if (stat.st_mode & libc::S_IFMT) == libc::S_IFDIR {
- newpath.push("");
- if let Some(newpath) = newpath.to_str() {
- result.push(newpath.to_owned());
- }
- continue;
- }
- }
- if let Some(newpath) = newpath.to_str() {
- result.push(newpath.to_owned());
- }
-
- }
- }
- }
-
- result
-}
-
fn main() {
- let cmd_def = CliCommand::new(
+ let create_cmd_def = CliCommand::new(
ApiMethod::new(
create_backup,
ObjectSchema::new("Create backup.")
)
))
.arg_param(vec!["filename", "target"])
- .completion_cb("filename", complete_file_name)
+ .completion_cb("filename", tools::complete_file_name)
+ .completion_cb("store", proxmox_backup::config::datastore::complete_datastore_name);
+
+ let list_cmd_def = CliCommand::new(
+ ApiMethod::new(
+ list_backups,
+ ObjectSchema::new("List backups.")
+ .required("store", StringSchema::new("Datastore name."))
+ ))
+ .arg_param(vec!["store"])
.completion_cb("store", proxmox_backup::config::datastore::complete_datastore_name);
+ let cmd_def = CliCommandMap::new()
+ .insert("create".to_owned(), create_cmd_def.into())
+ .insert("list".to_owned(), list_cmd_def.into());
+
if let Err(err) = run_cli_command(&cmd_def.into()) {
eprintln!("Error: {}", err);
if err.downcast::<UsageError>().is_ok() {