]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/catar/encoder.rs: add verbose flags
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 4 Mar 2019 07:01:09 +0000 (08:01 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 4 Mar 2019 07:01:09 +0000 (08:01 +0100)
src/bin/catar.rs
src/bin/proxmox-backup-client.rs
src/catar/encoder.rs
src/client/catar_backup_stream.rs

index 6a2f8c401e5fe4b1838c0358adeaa9110d5bc777..36a15c56a65e55d07f5cefdbd2763be3b89c9324 100644 (file)
@@ -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()?;
 
index 9e3711c526cca0584f7e84885ac825260a979d52..dec64f1ef5c8242c9e802fed6978da9b24b6ca19 100644 (file)
@@ -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.")
index 216f846458d05b655c20d3e886254ca01373f942..06a1c30721cb5294c34b082b1eae7b5fb4d29763 100644 (file)
@@ -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)) => {
index 17f7fd99a5358ed91c67c1fa440c2cc429f2097a..139e36bbb687f02982c6d2452a87982fc4b2b8b4 100644 (file)
@@ -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)
     }
 }