]>
git.proxmox.com Git - proxmox-backup.git/blob - src/bin/pxar.rs
1 extern crate proxmox_backup
;
5 use proxmox_backup
::tools
;
6 use proxmox_backup
::cli
::*;
7 use proxmox_backup
::api_schema
::*;
8 use proxmox_backup
::api_schema
::router
::*;
10 use serde_json
::{Value}
;
13 use std
::path
::{Path, PathBuf}
;
14 use std
::fs
::OpenOptions
;
15 use std
::os
::unix
::fs
::OpenOptionsExt
;
17 use proxmox_backup
::pxar
;
22 _rpcenv
: &mut dyn RpcEnvironment
,
23 ) -> Result
<Value
, Error
> {
25 let archive
= tools
::required_string_param(¶m
, "archive")?
;
26 let file
= std
::fs
::File
::open(archive
)?
;
28 let mut reader
= std
::io
::BufReader
::new(file
);
30 let mut feature_flags
= pxar
::CA_FORMAT_DEFAULT
;
31 feature_flags ^
= pxar
::CA_FORMAT_WITH_XATTRS
;
32 feature_flags ^
= pxar
::CA_FORMAT_WITH_FCAPS
;
33 let mut decoder
= pxar
::SequentialDecoder
::new(&mut reader
, feature_flags
);
35 let stdout
= std
::io
::stdout();
36 let mut out
= stdout
.lock();
38 let mut path
= PathBuf
::from(".");
39 decoder
.dump_entry(&mut path
, false, &mut out
)?
;
47 _rpcenv
: &mut dyn RpcEnvironment
,
48 ) -> Result
<Value
, Error
> {
50 let archive
= tools
::required_string_param(¶m
, "archive")?
;
51 let with_xattrs
= param
["with-xattrs"].as_bool().unwrap_or(false);
52 let with_fcaps
= param
["with-fcaps"].as_bool().unwrap_or(false);
53 let with_acls
= param
["with-acls"].as_bool().unwrap_or(false);
54 let file
= std
::fs
::File
::open(archive
)?
;
56 let mut reader
= std
::io
::BufReader
::new(file
);
58 let mut feature_flags
= pxar
::CA_FORMAT_DEFAULT
;
60 feature_flags ^
= pxar
::CA_FORMAT_WITH_XATTRS
;
63 feature_flags ^
= pxar
::CA_FORMAT_WITH_FCAPS
;
66 feature_flags ^
= pxar
::CA_FORMAT_WITH_ACL
;
68 let mut decoder
= pxar
::SequentialDecoder
::new(&mut reader
, feature_flags
);
70 let stdout
= std
::io
::stdout();
71 let mut out
= stdout
.lock();
73 println
!("PXAR dump: {}", archive
);
75 let mut path
= PathBuf
::new();
76 decoder
.dump_entry(&mut path
, true, &mut out
)?
;
84 _rpcenv
: &mut dyn RpcEnvironment
,
85 ) -> Result
<Value
, Error
> {
87 let archive
= tools
::required_string_param(¶m
, "archive")?
;
88 let target
= tools
::required_string_param(¶m
, "target")?
;
89 let verbose
= param
["verbose"].as_bool().unwrap_or(false);
90 let no_xattrs
= param
["no-xattrs"].as_bool().unwrap_or(false);
91 let no_fcaps
= param
["no-fcaps"].as_bool().unwrap_or(false);
92 let no_acls
= param
["no-acls"].as_bool().unwrap_or(false);
94 let file
= std
::fs
::File
::open(archive
)?
;
96 let mut reader
= std
::io
::BufReader
::new(file
);
97 let mut feature_flags
= pxar
::CA_FORMAT_DEFAULT
;
99 feature_flags ^
= pxar
::CA_FORMAT_WITH_XATTRS
;
102 feature_flags ^
= pxar
::CA_FORMAT_WITH_FCAPS
;
105 feature_flags ^
= pxar
::CA_FORMAT_WITH_ACL
;
108 let mut decoder
= pxar
::SequentialDecoder
::new(&mut reader
, feature_flags
);
110 decoder
.restore(Path
::new(target
), & |path
| {
112 println
!("{:?}", path
);
123 _rpcenv
: &mut dyn RpcEnvironment
,
124 ) -> Result
<Value
, Error
> {
126 let archive
= tools
::required_string_param(¶m
, "archive")?
;
127 let source
= tools
::required_string_param(¶m
, "source")?
;
128 let verbose
= param
["verbose"].as_bool().unwrap_or(false);
129 let all_file_systems
= param
["all-file-systems"].as_bool().unwrap_or(false);
130 let no_xattrs
= param
["no-xattrs"].as_bool().unwrap_or(false);
131 let no_fcaps
= param
["no-fcaps"].as_bool().unwrap_or(false);
132 let no_acls
= param
["no-acls"].as_bool().unwrap_or(false);
134 let source
= PathBuf
::from(source
);
136 let mut dir
= nix
::dir
::Dir
::open(
137 &source
, nix
::fcntl
::OFlag
::O_NOFOLLOW
, nix
::sys
::stat
::Mode
::empty())?
;
139 let file
= OpenOptions
::new()
145 let mut writer
= std
::io
::BufWriter
::with_capacity(1024*1024, file
);
146 let mut feature_flags
= pxar
::CA_FORMAT_DEFAULT
;
148 feature_flags ^
= pxar
::CA_FORMAT_WITH_XATTRS
;
151 feature_flags ^
= pxar
::CA_FORMAT_WITH_FCAPS
;
154 feature_flags ^
= pxar
::CA_FORMAT_WITH_ACL
;
157 pxar
::Encoder
::encode(source
, &mut dir
, &mut writer
, all_file_systems
, verbose
, feature_flags
)?
;
166 let cmd_def
= CliCommandMap
::new()
167 .insert("create", CliCommand
::new(
170 ObjectSchema
::new("Create new .pxar archive.")
171 .required("archive", StringSchema
::new("Archive name"))
172 .required("source", StringSchema
::new("Source directory."))
173 .optional("verbose", BooleanSchema
::new("Verbose output.").default(false))
174 .optional("no-xattrs", BooleanSchema
::new("Ignore extended file attributes.").default(false))
175 .optional("no-fcaps", BooleanSchema
::new("Ignore file capabilities.").default(false))
176 .optional("no-acls", BooleanSchema
::new("Ignore access control list entries.").default(false))
177 .optional("all-file-systems", BooleanSchema
::new("Include mounted sudirs.").default(false))
179 .arg_param(vec
!["archive", "source"])
180 .completion_cb("archive", tools
::complete_file_name
)
181 .completion_cb("source", tools
::complete_file_name
)
184 .insert("extract", CliCommand
::new(
187 ObjectSchema
::new("Extract an archive.")
188 .required("archive", StringSchema
::new("Archive name."))
189 .required("target", StringSchema
::new("Target directory."))
190 .optional("verbose", BooleanSchema
::new("Verbose output.").default(false))
191 .optional("no-xattrs", BooleanSchema
::new("Ignore extended file attributes.").default(false))
192 .optional("no-fcaps", BooleanSchema
::new("Ignore file capabilities.").default(false))
193 .optional("no-acls", BooleanSchema
::new("Ignore access control list entries.").default(false))
195 .arg_param(vec
!["archive", "target"])
196 .completion_cb("archive", tools
::complete_file_name
)
197 .completion_cb("target", tools
::complete_file_name
)
200 .insert("list", CliCommand
::new(
203 ObjectSchema
::new("List the contents of an archive.")
204 .required("archive", StringSchema
::new("Archive name."))
206 .arg_param(vec
!["archive"])
207 .completion_cb("archive", tools
::complete_file_name
)
210 .insert("dump", CliCommand
::new(
213 ObjectSchema
::new("Textual dump of archive contents (debug toolkit).")
214 .required("archive", StringSchema
::new("Archive name."))
215 .optional("with-xattrs", BooleanSchema
::new("Dump extended file attributes.").default(false))
216 .optional("with-fcaps", BooleanSchema
::new("Dump file capabilities.").default(false))
217 .optional("with-acls", BooleanSchema
::new("Dump access control list entries.").default(false))
219 .arg_param(vec
!["archive"])
220 .completion_cb("archive", tools
::complete_file_name
)
224 run_cli_command(cmd_def
.into());