2018-12-30 17:01:20 +00:00
|
|
|
extern crate proxmox_backup;
|
|
|
|
|
2020-04-17 12:11:25 +00:00
|
|
|
use anyhow::{format_err, Error};
|
2018-12-30 17:01:20 +00:00
|
|
|
|
2019-11-21 12:10:49 +00:00
|
|
|
use proxmox::{sortable, identity};
|
2019-11-21 13:53:15 +00:00
|
|
|
use proxmox::api::{ApiHandler, ApiMethod, RpcEnvironment};
|
|
|
|
use proxmox::api::schema::*;
|
2019-12-02 10:56:29 +00:00
|
|
|
use proxmox::api::cli::*;
|
2019-11-21 12:10:49 +00:00
|
|
|
|
2019-01-20 08:55:20 +00:00
|
|
|
use proxmox_backup::tools;
|
2018-12-30 17:01:20 +00:00
|
|
|
|
|
|
|
use serde_json::{Value};
|
|
|
|
|
2019-03-14 16:43:11 +00:00
|
|
|
use std::io::Write;
|
2019-03-15 07:03:44 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
2019-05-27 12:16:13 +00:00
|
|
|
use std::fs::OpenOptions;
|
2019-08-08 10:49:20 +00:00
|
|
|
use std::ffi::OsStr;
|
2019-05-27 12:16:13 +00:00
|
|
|
use std::os::unix::fs::OpenOptionsExt;
|
2019-07-16 16:19:45 +00:00
|
|
|
use std::os::unix::io::AsRawFd;
|
2019-07-24 05:48:59 +00:00
|
|
|
use std::collections::HashSet;
|
2018-12-30 17:01:20 +00:00
|
|
|
|
2019-03-15 07:24:32 +00:00
|
|
|
use proxmox_backup::pxar;
|
2019-01-06 16:42:23 +00:00
|
|
|
|
2019-07-16 06:31:40 +00:00
|
|
|
fn dump_archive_from_reader<R: std::io::Read>(
|
|
|
|
reader: &mut R,
|
|
|
|
feature_flags: u64,
|
|
|
|
verbose: bool,
|
|
|
|
) -> Result<(), Error> {
|
2019-11-26 08:56:48 +00:00
|
|
|
let mut decoder = pxar::SequentialDecoder::new(reader, feature_flags);
|
2019-07-05 10:32:15 +00:00
|
|
|
|
|
|
|
let stdout = std::io::stdout();
|
|
|
|
let mut out = stdout.lock();
|
|
|
|
|
|
|
|
let mut path = PathBuf::new();
|
2019-07-16 06:31:40 +00:00
|
|
|
decoder.dump_entry(&mut path, verbose, &mut out)?;
|
2019-07-05 10:32:15 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-01-26 13:50:37 +00:00
|
|
|
fn dump_archive(
|
|
|
|
param: Value,
|
|
|
|
_info: &ApiMethod,
|
2019-06-07 11:10:56 +00:00
|
|
|
_rpcenv: &mut dyn RpcEnvironment,
|
2019-01-26 13:50:37 +00:00
|
|
|
) -> Result<Value, Error> {
|
2018-12-30 17:01:20 +00:00
|
|
|
|
2019-01-26 13:50:37 +00:00
|
|
|
let archive = tools::required_string_param(¶m, "archive")?;
|
2019-07-16 06:31:40 +00:00
|
|
|
let verbose = param["verbose"].as_bool().unwrap_or(false);
|
2018-12-30 17:01:20 +00:00
|
|
|
|
2019-08-02 13:19:33 +00:00
|
|
|
let feature_flags = pxar::flags::DEFAULT;
|
2018-12-30 17:01:20 +00:00
|
|
|
|
2019-07-05 10:32:15 +00:00
|
|
|
if archive == "-" {
|
|
|
|
let stdin = std::io::stdin();
|
|
|
|
let mut reader = stdin.lock();
|
2019-07-16 06:31:40 +00:00
|
|
|
dump_archive_from_reader(&mut reader, feature_flags, verbose)?;
|
2019-07-05 10:32:15 +00:00
|
|
|
} else {
|
2019-07-16 06:38:02 +00:00
|
|
|
if verbose { println!("PXAR dump: {}", archive); }
|
2019-07-05 10:32:15 +00:00
|
|
|
let file = std::fs::File::open(archive)?;
|
|
|
|
let mut reader = std::io::BufReader::new(file);
|
2019-07-16 06:31:40 +00:00
|
|
|
dump_archive_from_reader(&mut reader, feature_flags, verbose)?;
|
2019-07-05 10:39:25 +00:00
|
|
|
}
|
2018-12-30 17:01:20 +00:00
|
|
|
|
|
|
|
Ok(Value::Null)
|
|
|
|
}
|
|
|
|
|
2019-07-16 16:19:45 +00:00
|
|
|
fn extract_archive_from_reader<R: std::io::Read>(
|
|
|
|
reader: &mut R,
|
|
|
|
target: &str,
|
|
|
|
feature_flags: u64,
|
2019-07-29 12:01:45 +00:00
|
|
|
allow_existing_dirs: bool,
|
2019-07-16 16:19:45 +00:00
|
|
|
verbose: bool,
|
2019-08-02 15:02:24 +00:00
|
|
|
pattern: Option<Vec<pxar::MatchPattern>>
|
2019-07-16 16:19:45 +00:00
|
|
|
) -> Result<(), Error> {
|
2019-11-26 08:56:48 +00:00
|
|
|
let mut decoder = pxar::SequentialDecoder::new(reader, feature_flags);
|
|
|
|
decoder.set_callback(move |path| {
|
2019-07-05 10:39:25 +00:00
|
|
|
if verbose {
|
|
|
|
println!("{:?}", path);
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
});
|
2019-07-29 12:01:45 +00:00
|
|
|
decoder.set_allow_existing_dirs(allow_existing_dirs);
|
2019-07-05 10:39:25 +00:00
|
|
|
|
2019-10-25 16:04:37 +00:00
|
|
|
let pattern = pattern.unwrap_or_else(Vec::new);
|
2019-07-16 16:19:45 +00:00
|
|
|
decoder.restore(Path::new(target), &pattern)?;
|
2019-07-05 10:39:25 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-03-15 07:03:44 +00:00
|
|
|
fn extract_archive(
|
|
|
|
param: Value,
|
|
|
|
_info: &ApiMethod,
|
2019-06-07 11:10:56 +00:00
|
|
|
_rpcenv: &mut dyn RpcEnvironment,
|
2019-03-15 07:03:44 +00:00
|
|
|
) -> Result<Value, Error> {
|
|
|
|
|
|
|
|
let archive = tools::required_string_param(¶m, "archive")?;
|
2019-07-16 13:45:17 +00:00
|
|
|
let target = param["target"].as_str().unwrap_or(".");
|
2019-03-15 07:03:44 +00:00
|
|
|
let verbose = param["verbose"].as_bool().unwrap_or(false);
|
2019-05-22 15:50:43 +00:00
|
|
|
let no_xattrs = param["no-xattrs"].as_bool().unwrap_or(false);
|
|
|
|
let no_fcaps = param["no-fcaps"].as_bool().unwrap_or(false);
|
2019-05-28 09:16:21 +00:00
|
|
|
let no_acls = param["no-acls"].as_bool().unwrap_or(false);
|
2019-08-01 15:51:59 +00:00
|
|
|
let no_device_nodes = param["no-device-nodes"].as_bool().unwrap_or(false);
|
|
|
|
let no_fifos = param["no-fifos"].as_bool().unwrap_or(false);
|
|
|
|
let no_sockets = param["no-sockets"].as_bool().unwrap_or(false);
|
2019-07-29 12:01:45 +00:00
|
|
|
let allow_existing_dirs = param["allow-existing-dirs"].as_bool().unwrap_or(false);
|
2019-07-16 16:19:45 +00:00
|
|
|
let files_from = param["files-from"].as_str();
|
2019-07-18 09:35:51 +00:00
|
|
|
let empty = Vec::new();
|
|
|
|
let arg_pattern = param["pattern"].as_array().unwrap_or(&empty);
|
2019-03-15 07:03:44 +00:00
|
|
|
|
2019-08-02 13:19:33 +00:00
|
|
|
let mut feature_flags = pxar::flags::DEFAULT;
|
2019-05-23 11:10:20 +00:00
|
|
|
if no_xattrs {
|
2019-08-02 13:19:33 +00:00
|
|
|
feature_flags ^= pxar::flags::WITH_XATTRS;
|
2019-05-23 11:10:20 +00:00
|
|
|
}
|
|
|
|
if no_fcaps {
|
2019-08-02 13:19:33 +00:00
|
|
|
feature_flags ^= pxar::flags::WITH_FCAPS;
|
2019-05-23 11:10:20 +00:00
|
|
|
}
|
2019-05-28 09:16:21 +00:00
|
|
|
if no_acls {
|
2019-08-02 13:19:33 +00:00
|
|
|
feature_flags ^= pxar::flags::WITH_ACL;
|
2019-05-28 09:16:21 +00:00
|
|
|
}
|
2019-08-01 15:51:59 +00:00
|
|
|
if no_device_nodes {
|
2019-08-02 13:19:33 +00:00
|
|
|
feature_flags ^= pxar::flags::WITH_DEVICE_NODES;
|
2019-08-01 15:51:59 +00:00
|
|
|
}
|
|
|
|
if no_fifos {
|
2019-08-02 13:19:33 +00:00
|
|
|
feature_flags ^= pxar::flags::WITH_FIFOS;
|
2019-08-01 15:51:59 +00:00
|
|
|
}
|
|
|
|
if no_sockets {
|
2019-08-02 13:19:33 +00:00
|
|
|
feature_flags ^= pxar::flags::WITH_SOCKETS;
|
2019-08-01 15:51:59 +00:00
|
|
|
}
|
2019-03-15 07:03:44 +00:00
|
|
|
|
2019-07-18 09:35:51 +00:00
|
|
|
let mut pattern_list = Vec::new();
|
|
|
|
if let Some(filename) = files_from {
|
|
|
|
let dir = nix::dir::Dir::open("./", nix::fcntl::OFlag::O_RDONLY, nix::sys::stat::Mode::empty())?;
|
2019-08-02 15:02:24 +00:00
|
|
|
if let Some((mut pattern, _, _)) = pxar::MatchPattern::from_file(dir.as_raw_fd(), filename)? {
|
2019-07-18 09:35:51 +00:00
|
|
|
pattern_list.append(&mut pattern);
|
|
|
|
}
|
|
|
|
}
|
2019-07-16 16:19:45 +00:00
|
|
|
|
2019-07-18 09:35:51 +00:00
|
|
|
for s in arg_pattern {
|
|
|
|
let l = s.as_str().ok_or_else(|| format_err!("Invalid pattern string slice"))?;
|
2019-08-02 15:02:24 +00:00
|
|
|
let p = pxar::MatchPattern::from_line(l.as_bytes())?
|
2019-07-18 09:35:51 +00:00
|
|
|
.ok_or_else(|| format_err!("Invalid match pattern in arguments"))?;
|
|
|
|
pattern_list.push(p);
|
|
|
|
}
|
|
|
|
|
2019-10-25 16:04:37 +00:00
|
|
|
let pattern = if pattern_list.is_empty() {
|
2019-07-18 09:35:51 +00:00
|
|
|
None
|
2019-10-25 16:04:37 +00:00
|
|
|
} else {
|
|
|
|
Some(pattern_list)
|
2019-07-16 16:19:45 +00:00
|
|
|
};
|
|
|
|
|
2019-07-05 10:39:25 +00:00
|
|
|
if archive == "-" {
|
|
|
|
let stdin = std::io::stdin();
|
|
|
|
let mut reader = stdin.lock();
|
2019-07-29 12:01:45 +00:00
|
|
|
extract_archive_from_reader(&mut reader, target, feature_flags, allow_existing_dirs, verbose, pattern)?;
|
2019-07-05 10:39:25 +00:00
|
|
|
} else {
|
2019-07-19 05:01:57 +00:00
|
|
|
if verbose { println!("PXAR extract: {}", archive); }
|
2019-07-05 10:39:25 +00:00
|
|
|
let file = std::fs::File::open(archive)?;
|
|
|
|
let mut reader = std::io::BufReader::new(file);
|
2019-07-29 12:01:45 +00:00
|
|
|
extract_archive_from_reader(&mut reader, target, feature_flags, allow_existing_dirs, verbose, pattern)?;
|
2019-07-05 10:39:25 +00:00
|
|
|
}
|
2019-03-15 07:03:44 +00:00
|
|
|
|
|
|
|
Ok(Value::Null)
|
|
|
|
}
|
|
|
|
|
2019-01-26 13:50:37 +00:00
|
|
|
fn create_archive(
|
|
|
|
param: Value,
|
|
|
|
_info: &ApiMethod,
|
2019-06-07 11:10:56 +00:00
|
|
|
_rpcenv: &mut dyn RpcEnvironment,
|
2019-01-26 13:50:37 +00:00
|
|
|
) -> Result<Value, Error> {
|
2018-12-30 17:01:20 +00:00
|
|
|
|
2019-01-26 13:50:37 +00:00
|
|
|
let archive = tools::required_string_param(¶m, "archive")?;
|
|
|
|
let source = tools::required_string_param(¶m, "source")?;
|
2019-03-08 07:20:56 +00:00
|
|
|
let verbose = param["verbose"].as_bool().unwrap_or(false);
|
2019-03-08 08:28:12 +00:00
|
|
|
let all_file_systems = param["all-file-systems"].as_bool().unwrap_or(false);
|
2019-05-22 15:50:43 +00:00
|
|
|
let no_xattrs = param["no-xattrs"].as_bool().unwrap_or(false);
|
|
|
|
let no_fcaps = param["no-fcaps"].as_bool().unwrap_or(false);
|
2019-05-28 09:16:21 +00:00
|
|
|
let no_acls = param["no-acls"].as_bool().unwrap_or(false);
|
2019-08-01 15:51:59 +00:00
|
|
|
let no_device_nodes = param["no-device-nodes"].as_bool().unwrap_or(false);
|
|
|
|
let no_fifos = param["no-fifos"].as_bool().unwrap_or(false);
|
|
|
|
let no_sockets = param["no-sockets"].as_bool().unwrap_or(false);
|
2019-10-22 13:07:51 +00:00
|
|
|
let empty = Vec::new();
|
|
|
|
let exclude_pattern = param["exclude"].as_array().unwrap_or(&empty);
|
2020-01-10 11:50:06 +00:00
|
|
|
let entries_max = param["entries-max"].as_u64().unwrap_or(pxar::ENCODER_MAX_ENTRIES as u64);
|
2019-01-07 12:25:41 +00:00
|
|
|
|
2019-07-24 05:48:59 +00:00
|
|
|
let devices = if all_file_systems { None } else { Some(HashSet::new()) };
|
|
|
|
|
2019-03-15 07:03:44 +00:00
|
|
|
let source = PathBuf::from(source);
|
2019-01-07 12:25:41 +00:00
|
|
|
|
|
|
|
let mut dir = nix::dir::Dir::open(
|
|
|
|
&source, nix::fcntl::OFlag::O_NOFOLLOW, nix::sys::stat::Mode::empty())?;
|
|
|
|
|
2019-05-27 12:16:13 +00:00
|
|
|
let file = OpenOptions::new()
|
2019-01-07 12:25:41 +00:00
|
|
|
.create_new(true)
|
|
|
|
.write(true)
|
2019-05-27 12:16:13 +00:00
|
|
|
.mode(0o640)
|
2019-01-07 12:25:41 +00:00
|
|
|
.open(archive)?;
|
|
|
|
|
|
|
|
let mut writer = std::io::BufWriter::with_capacity(1024*1024, file);
|
2019-08-02 13:19:33 +00:00
|
|
|
let mut feature_flags = pxar::flags::DEFAULT;
|
2019-05-23 11:10:20 +00:00
|
|
|
if no_xattrs {
|
2019-08-02 13:19:33 +00:00
|
|
|
feature_flags ^= pxar::flags::WITH_XATTRS;
|
2019-05-23 11:10:20 +00:00
|
|
|
}
|
|
|
|
if no_fcaps {
|
2019-08-02 13:19:33 +00:00
|
|
|
feature_flags ^= pxar::flags::WITH_FCAPS;
|
2019-05-23 11:10:20 +00:00
|
|
|
}
|
2019-05-28 09:16:21 +00:00
|
|
|
if no_acls {
|
2019-08-02 13:19:33 +00:00
|
|
|
feature_flags ^= pxar::flags::WITH_ACL;
|
2019-05-28 09:16:21 +00:00
|
|
|
}
|
2019-08-01 15:51:59 +00:00
|
|
|
if no_device_nodes {
|
2019-08-02 13:19:33 +00:00
|
|
|
feature_flags ^= pxar::flags::WITH_DEVICE_NODES;
|
2019-08-01 15:51:59 +00:00
|
|
|
}
|
|
|
|
if no_fifos {
|
2019-08-02 13:19:33 +00:00
|
|
|
feature_flags ^= pxar::flags::WITH_FIFOS;
|
2019-08-01 15:51:59 +00:00
|
|
|
}
|
|
|
|
if no_sockets {
|
2019-08-02 13:19:33 +00:00
|
|
|
feature_flags ^= pxar::flags::WITH_SOCKETS;
|
2019-08-01 15:51:59 +00:00
|
|
|
}
|
2019-05-23 11:10:20 +00:00
|
|
|
|
2019-10-22 13:07:51 +00:00
|
|
|
let mut pattern_list = Vec::new();
|
|
|
|
for s in exclude_pattern {
|
|
|
|
let l = s.as_str().ok_or_else(|| format_err!("Invalid pattern string slice"))?;
|
|
|
|
let p = pxar::MatchPattern::from_line(l.as_bytes())?
|
|
|
|
.ok_or_else(|| format_err!("Invalid match pattern in arguments"))?;
|
|
|
|
pattern_list.push(p);
|
|
|
|
}
|
|
|
|
|
2019-08-16 10:27:17 +00:00
|
|
|
let catalog = None::<&mut pxar::catalog::DummyCatalogWriter>;
|
2019-10-22 13:07:51 +00:00
|
|
|
pxar::Encoder::encode(
|
|
|
|
source,
|
|
|
|
&mut dir,
|
|
|
|
&mut writer,
|
|
|
|
catalog,
|
|
|
|
devices,
|
|
|
|
verbose,
|
|
|
|
false,
|
|
|
|
feature_flags,
|
|
|
|
pattern_list,
|
2020-01-10 11:50:06 +00:00
|
|
|
entries_max as usize,
|
2019-10-22 13:07:51 +00:00
|
|
|
)?;
|
2018-12-30 17:01:20 +00:00
|
|
|
|
2019-01-07 12:25:41 +00:00
|
|
|
writer.flush()?;
|
2018-12-30 17:01:20 +00:00
|
|
|
|
|
|
|
Ok(Value::Null)
|
|
|
|
}
|
|
|
|
|
2019-08-08 10:49:20 +00:00
|
|
|
/// Mount the archive to the provided mountpoint via FUSE.
|
|
|
|
fn mount_archive(
|
|
|
|
param: Value,
|
|
|
|
_info: &ApiMethod,
|
|
|
|
_rpcenv: &mut dyn RpcEnvironment,
|
|
|
|
) -> Result<Value, Error> {
|
|
|
|
let archive = tools::required_string_param(¶m, "archive")?;
|
|
|
|
let mountpoint = tools::required_string_param(¶m, "mountpoint")?;
|
|
|
|
let verbose = param["verbose"].as_bool().unwrap_or(false);
|
2019-08-22 14:39:04 +00:00
|
|
|
let no_mt = param["no-mt"].as_bool().unwrap_or(false);
|
2019-08-08 10:49:20 +00:00
|
|
|
|
|
|
|
let archive = Path::new(archive);
|
|
|
|
let mountpoint = Path::new(mountpoint);
|
|
|
|
let options = OsStr::new("ro,default_permissions");
|
2019-11-26 09:56:41 +00:00
|
|
|
let mut session = pxar::fuse::Session::from_path(&archive, &options, verbose)
|
2019-08-08 10:49:20 +00:00
|
|
|
.map_err(|err| format_err!("pxar mount failed: {}", err))?;
|
2019-09-19 14:33:08 +00:00
|
|
|
// Mount the session and deamonize if verbose is not set
|
|
|
|
session.mount(&mountpoint, !verbose)?;
|
2019-08-22 14:39:04 +00:00
|
|
|
session.run_loop(!no_mt)?;
|
2019-08-08 10:49:20 +00:00
|
|
|
|
|
|
|
Ok(Value::Null)
|
|
|
|
}
|
|
|
|
|
2019-11-21 12:10:49 +00:00
|
|
|
#[sortable]
|
2019-11-21 08:36:41 +00:00
|
|
|
const API_METHOD_CREATE_ARCHIVE: ApiMethod = ApiMethod::new(
|
|
|
|
&ApiHandler::Sync(&create_archive),
|
|
|
|
&ObjectSchema::new(
|
|
|
|
"Create new .pxar archive.",
|
2019-11-21 12:10:49 +00:00
|
|
|
&sorted!([
|
2019-11-21 08:36:41 +00:00
|
|
|
(
|
|
|
|
"archive",
|
|
|
|
false,
|
|
|
|
&StringSchema::new("Archive name").schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"source",
|
|
|
|
false,
|
|
|
|
&StringSchema::new("Source directory.").schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"verbose",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Verbose output.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no-xattrs",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Ignore extended file attributes.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no-fcaps",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Ignore file capabilities.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no-acls",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Ignore access control list entries.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"all-file-systems",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Include mounted sudirs.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no-device-nodes",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Ignore device nodes.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no-fifos",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Ignore fifos.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no-sockets",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Ignore sockets.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"exclude",
|
|
|
|
true,
|
|
|
|
&ArraySchema::new(
|
|
|
|
"List of paths or pattern matching files to exclude.",
|
|
|
|
&StringSchema::new("Path or pattern matching files to restore.").schema()
|
|
|
|
).schema()
|
|
|
|
),
|
2020-01-10 11:50:06 +00:00
|
|
|
(
|
|
|
|
"entries-max",
|
|
|
|
true,
|
|
|
|
&IntegerSchema::new("Max number of entries loaded at once into memory")
|
|
|
|
.default(pxar::ENCODER_MAX_ENTRIES as isize)
|
|
|
|
.minimum(0)
|
|
|
|
.maximum(std::isize::MAX)
|
|
|
|
.schema()
|
|
|
|
),
|
2019-11-21 12:10:49 +00:00
|
|
|
]),
|
2019-11-21 08:36:41 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-11-21 12:10:49 +00:00
|
|
|
#[sortable]
|
2019-11-21 08:36:41 +00:00
|
|
|
const API_METHOD_EXTRACT_ARCHIVE: ApiMethod = ApiMethod::new(
|
|
|
|
&ApiHandler::Sync(&extract_archive),
|
|
|
|
&ObjectSchema::new(
|
|
|
|
"Extract an archive.",
|
2019-11-21 12:10:49 +00:00
|
|
|
&sorted!([
|
2019-11-21 08:36:41 +00:00
|
|
|
(
|
|
|
|
"archive",
|
|
|
|
false,
|
|
|
|
&StringSchema::new("Archive name.").schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"pattern",
|
|
|
|
true,
|
|
|
|
&ArraySchema::new(
|
|
|
|
"List of paths or pattern matching files to restore",
|
|
|
|
&StringSchema::new("Path or pattern matching files to restore.").schema()
|
|
|
|
).schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"target",
|
|
|
|
true,
|
|
|
|
&StringSchema::new("Target directory.").schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"verbose",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Verbose output.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no-xattrs",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Ignore extended file attributes.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no-fcaps",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Ignore file capabilities.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no-acls",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Ignore access control list entries.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"allow-existing-dirs",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Allows directories to already exist on restore.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"files-from",
|
|
|
|
true,
|
|
|
|
&StringSchema::new("Match pattern for files to restore.").schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no-device-nodes",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Ignore device nodes.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no-fifos",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Ignore fifos.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no-sockets",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Ignore sockets.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
2019-11-21 12:10:49 +00:00
|
|
|
]),
|
2019-11-21 08:36:41 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-11-21 12:10:49 +00:00
|
|
|
#[sortable]
|
2019-11-21 08:36:41 +00:00
|
|
|
const API_METHOD_MOUNT_ARCHIVE: ApiMethod = ApiMethod::new(
|
|
|
|
&ApiHandler::Sync(&mount_archive),
|
|
|
|
&ObjectSchema::new(
|
|
|
|
"Mount the archive as filesystem via FUSE.",
|
2019-11-21 12:10:49 +00:00
|
|
|
&sorted!([
|
2019-11-21 08:36:41 +00:00
|
|
|
(
|
|
|
|
"archive",
|
|
|
|
false,
|
|
|
|
&StringSchema::new("Archive name.").schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"mountpoint",
|
|
|
|
false,
|
|
|
|
&StringSchema::new("Mountpoint for the filesystem root.").schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"verbose",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Verbose output, keeps process running in foreground (for debugging).")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"no-mt",
|
|
|
|
true,
|
|
|
|
&BooleanSchema::new("Run in single threaded mode (for debugging).")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
2019-11-21 12:10:49 +00:00
|
|
|
]),
|
2019-11-21 08:36:41 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-11-21 12:10:49 +00:00
|
|
|
#[sortable]
|
2019-11-21 08:36:41 +00:00
|
|
|
const API_METHOD_DUMP_ARCHIVE: ApiMethod = ApiMethod::new(
|
|
|
|
&ApiHandler::Sync(&dump_archive),
|
|
|
|
&ObjectSchema::new(
|
|
|
|
"List the contents of an archive.",
|
2019-11-21 12:10:49 +00:00
|
|
|
&sorted!([
|
2019-11-21 08:36:41 +00:00
|
|
|
( "archive", false, &StringSchema::new("Archive name.").schema()),
|
|
|
|
( "verbose", true, &BooleanSchema::new("Verbose output.")
|
|
|
|
.default(false)
|
|
|
|
.schema()
|
|
|
|
),
|
2019-11-21 12:10:49 +00:00
|
|
|
])
|
2019-11-21 08:36:41 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2018-12-30 17:01:20 +00:00
|
|
|
fn main() {
|
|
|
|
|
|
|
|
let cmd_def = CliCommandMap::new()
|
2019-11-21 08:36:41 +00:00
|
|
|
.insert("create", CliCommand::new(&API_METHOD_CREATE_ARCHIVE)
|
2020-04-15 04:31:46 +00:00
|
|
|
.arg_param(&["archive", "source"])
|
2019-01-20 08:55:20 +00:00
|
|
|
.completion_cb("archive", tools::complete_file_name)
|
|
|
|
.completion_cb("source", tools::complete_file_name)
|
2018-12-30 17:01:20 +00:00
|
|
|
)
|
2019-11-21 08:36:41 +00:00
|
|
|
.insert("extract", CliCommand::new(&API_METHOD_EXTRACT_ARCHIVE)
|
2020-04-15 04:41:37 +00:00
|
|
|
.arg_param(&["archive", "target"])
|
2019-03-15 07:03:44 +00:00
|
|
|
.completion_cb("archive", tools::complete_file_name)
|
|
|
|
.completion_cb("target", tools::complete_file_name)
|
2019-07-16 16:19:45 +00:00
|
|
|
.completion_cb("files-from", tools::complete_file_name)
|
2019-12-09 16:40:34 +00:00
|
|
|
)
|
2019-11-21 08:36:41 +00:00
|
|
|
.insert("mount", CliCommand::new(&API_METHOD_MOUNT_ARCHIVE)
|
2019-11-24 10:00:53 +00:00
|
|
|
.arg_param(&["archive", "mountpoint"])
|
2019-08-08 10:49:20 +00:00
|
|
|
.completion_cb("archive", tools::complete_file_name)
|
|
|
|
.completion_cb("mountpoint", tools::complete_file_name)
|
|
|
|
)
|
2019-11-21 08:36:41 +00:00
|
|
|
.insert("list", CliCommand::new(&API_METHOD_DUMP_ARCHIVE)
|
2019-11-24 10:00:53 +00:00
|
|
|
.arg_param(&["archive"])
|
2019-01-20 08:55:20 +00:00
|
|
|
.completion_cb("archive", tools::complete_file_name)
|
2018-12-30 17:01:20 +00:00
|
|
|
);
|
|
|
|
|
2020-05-06 05:51:05 +00:00
|
|
|
let rpcenv = CliEnvironment::new();
|
|
|
|
run_cli_command(cmd_def, rpcenv, None);
|
2018-12-30 17:01:20 +00:00
|
|
|
}
|