diff --git a/src/bin/catar.rs b/src/bin/catar.rs index 6a2f8c40..36a15c56 100644 --- a/src/bin/catar.rs +++ b/src/bin/catar.rs @@ -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()?; diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index 9e3711c5..dec64f1e 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -35,6 +35,7 @@ fn backup_directory>( archive_name: &str, backup_time: DateTime, chunk_size: Option, + verbose: bool, ) -> Result<(), Error> { let mut param = json!({ @@ -52,7 +53,7 @@ fn backup_directory>( 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.") diff --git a/src/catar/encoder.rs b/src/catar/encoder.rs index 216f8464..06a1c307 100644 --- a/src/catar/encoder.rs +++ b/src/catar/encoder.rs @@ -35,6 +35,7 @@ pub struct CaTarEncoder<'a, W: Write> { _size: usize, file_copy_buffer: Vec, devices: Option>, + 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>, - 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)) => { diff --git a/src/client/catar_backup_stream.rs b/src/client/catar_backup_stream.rs index 17f7fd99..139e36bb 100644 --- a/src/client/catar_backup_stream.rs +++ b/src/client/catar_backup_stream.rs @@ -36,7 +36,7 @@ impl Drop for CaTarBackupStream { impl CaTarBackupStream { - pub fn new(mut dir: Dir, path: PathBuf) -> Result { + pub fn new(mut dir: Dir, path: PathBuf, verbose: bool) -> Result { 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 { + pub fn open(dirname: &Path, verbose: bool) -> Result { 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) } }