src/catar/encoder.rs: add verbose flags
This commit is contained in:
parent
e0b8ce6424
commit
219ef0e6ca
@ -142,7 +142,7 @@ fn create_archive(
|
||||
|
||||
let mut writer = std::io::BufWriter::with_capacity(1024*1024, file);
|
||||
|
||||
CaTarEncoder::encode(source, &mut dir, None, &mut writer)?;
|
||||
CaTarEncoder::encode(source, &mut dir, None, &mut writer, false)?;
|
||||
|
||||
writer.flush()?;
|
||||
|
||||
|
@ -35,6 +35,7 @@ fn backup_directory<P: AsRef<Path>>(
|
||||
archive_name: &str,
|
||||
backup_time: DateTime<Utc>,
|
||||
chunk_size: Option<u64>,
|
||||
verbose: bool,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
let mut param = json!({
|
||||
@ -52,7 +53,7 @@ fn backup_directory<P: AsRef<Path>>(
|
||||
|
||||
let path = format!("api2/json/admin/datastore/{}/catar?{}", repo.store, query);
|
||||
|
||||
let stream = CaTarBackupStream::open(dir_path.as_ref())?;
|
||||
let stream = CaTarBackupStream::open(dir_path.as_ref(), verbose)?;
|
||||
|
||||
let body = Body::wrap_stream(stream);
|
||||
|
||||
@ -300,6 +301,8 @@ fn create_backup(
|
||||
|
||||
let repo = BackupRepository::parse(repo_url)?;
|
||||
|
||||
let verbose = param["verbose"].as_bool().unwrap_or(false);
|
||||
|
||||
let chunk_size_opt = param["chunk-size"].as_u64().map(|v| v*1024);
|
||||
|
||||
if let Some(size) = chunk_size_opt {
|
||||
@ -354,7 +357,7 @@ fn create_backup(
|
||||
|
||||
for (filename, target) in upload_list {
|
||||
flog!(log, "Upload '{}' to '{:?}' as {}", filename, repo, target);
|
||||
backup_directory(&mut client, &repo, &filename, &target, backup_time, chunk_size_opt)?;
|
||||
backup_directory(&mut client, &repo, &filename, &target, backup_time, chunk_size_opt, verbose)?;
|
||||
}
|
||||
|
||||
flog!(log, "Upload backup log");
|
||||
@ -432,6 +435,9 @@ fn main() {
|
||||
backup_source_schema,
|
||||
).min_length(1)
|
||||
)
|
||||
.optional(
|
||||
"verbose",
|
||||
BooleanSchema::new("Verbose output.").default(false))
|
||||
.optional(
|
||||
"chunk-size",
|
||||
IntegerSchema::new("Chunk size in KB. Must be a power of 2.")
|
||||
|
@ -35,6 +35,7 @@ pub struct CaTarEncoder<'a, W: Write> {
|
||||
_size: usize,
|
||||
file_copy_buffer: Vec<u8>,
|
||||
devices: Option<HashSet<u64>>,
|
||||
verbose: bool,
|
||||
}
|
||||
|
||||
impl <'a, W: Write> CaTarEncoder<'a, W> {
|
||||
@ -43,7 +44,8 @@ impl <'a, W: Write> CaTarEncoder<'a, W> {
|
||||
path: PathBuf,
|
||||
dir: &mut nix::dir::Dir,
|
||||
device_list: Option<Vec<u64>>,
|
||||
writer: &'a mut W
|
||||
writer: &'a mut W,
|
||||
verbose: bool,
|
||||
) -> Result<(), Error> {
|
||||
|
||||
const FILE_COPY_BUFFER_SIZE: usize = 1024*1024;
|
||||
@ -58,6 +60,7 @@ impl <'a, W: Write> CaTarEncoder<'a, W> {
|
||||
_size: 0,
|
||||
file_copy_buffer,
|
||||
devices: None,
|
||||
verbose,
|
||||
};
|
||||
|
||||
// todo: use scandirat??
|
||||
@ -85,6 +88,8 @@ impl <'a, W: Write> CaTarEncoder<'a, W> {
|
||||
me.devices = Some(devices);
|
||||
}
|
||||
|
||||
if verbose { println!("{:?}", me.current_path); }
|
||||
|
||||
me.encode_dir(dir, &stat, magic)?;
|
||||
|
||||
Ok(())
|
||||
@ -304,6 +309,8 @@ impl <'a, W: Write> CaTarEncoder<'a, W> {
|
||||
for filename in &name_list {
|
||||
self.current_path.push(std::ffi::OsStr::from_bytes(filename.as_bytes()));
|
||||
|
||||
if self.verbose { println!("{:?}", self.current_path); }
|
||||
|
||||
let stat = match nix::sys::stat::fstatat(rawfd, filename.as_ref(), nix::fcntl::AtFlags::AT_SYMLINK_NOFOLLOW) {
|
||||
Ok(stat) => stat,
|
||||
Err(nix::Error::Sys(Errno::ENOENT)) => {
|
||||
|
@ -36,7 +36,7 @@ impl Drop for CaTarBackupStream {
|
||||
|
||||
impl CaTarBackupStream {
|
||||
|
||||
pub fn new(mut dir: Dir, path: PathBuf) -> Result<Self, Error> {
|
||||
pub fn new(mut dir: Dir, path: PathBuf, verbose: bool) -> Result<Self, Error> {
|
||||
let mut buffer = Vec::with_capacity(4096);
|
||||
unsafe { buffer.set_len(buffer.capacity()); }
|
||||
|
||||
@ -44,7 +44,8 @@ impl CaTarBackupStream {
|
||||
|
||||
let child = thread::spawn(move|| {
|
||||
let mut writer = unsafe { std::fs::File::from_raw_fd(tx) };
|
||||
if let Err(err) = CaTarEncoder::encode(path, &mut dir, None, &mut writer) {
|
||||
let device_list = vec![];
|
||||
if let Err(err) = CaTarEncoder::encode(path, &mut dir, Some(device_list), &mut writer, verbose) {
|
||||
eprintln!("catar encode failed - {}", err);
|
||||
}
|
||||
});
|
||||
@ -54,12 +55,12 @@ impl CaTarBackupStream {
|
||||
Ok(Self { pipe: Some(pipe), buffer, child: Some(child) })
|
||||
}
|
||||
|
||||
pub fn open(dirname: &Path) -> Result<Self, Error> {
|
||||
pub fn open(dirname: &Path, verbose: bool) -> Result<Self, Error> {
|
||||
|
||||
let dir = nix::dir::Dir::open(dirname, OFlag::O_DIRECTORY, Mode::empty())?;
|
||||
let path = std::path::PathBuf::from(dirname);
|
||||
|
||||
Self::new(dir, path)
|
||||
Self::new(dir, path, verbose)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user