diff options
Diffstat (limited to 'src/cmd/backup.rs')
-rw-r--r-- | src/cmd/backup.rs | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/cmd/backup.rs b/src/cmd/backup.rs index 926b2b1..8f195eb 100644 --- a/src/cmd/backup.rs +++ b/src/cmd/backup.rs @@ -1,9 +1,12 @@ use crate::client::{BackupClient, ClientConfig}; use crate::fsiter::FsIterator; use crate::generation::Generation; +use indicatif::{ProgressBar, ProgressStyle}; use std::path::Path; use tempfile::NamedTempFile; +const GUESS_FILE_COUNT: u64 = 0; + pub fn backup(config: &Path, buffer_size: usize) -> anyhow::Result<()> { let config = ClientConfig::read_config(config)?; let client = BackupClient::new(&config.server_url)?; @@ -21,10 +24,21 @@ pub fn backup(config: &Path, buffer_size: usize) -> anyhow::Result<()> { // The fetching is in its own block so that the file handles // get closed and data flushed to disk. let mut gen = Generation::create(&dbname)?; - gen.insert_iter(FsIterator::new(&config.root).map(|entry| match entry { - Err(err) => Err(err), - Ok(entry) => client.upload_filesystem_entry(entry, buffer_size), + let progress = create_progress_bar(GUESS_FILE_COUNT); + progress.enable_steady_tick(100); + gen.insert_iter(FsIterator::new(&config.root).map(|entry| { + progress.inc(1); + match entry { + Err(err) => Err(err), + Ok(entry) => { + progress.set_message(&format!("{}", entry.path().display())); + client.upload_filesystem_entry(entry, buffer_size) + } + } }))?; + progress.set_length(gen.file_count()); + progress.finish(); + println!("file count: {}", gen.file_count()); } // Upload the SQLite file, i.e., the named temporary file, which @@ -37,3 +51,16 @@ pub fn backup(config: &Path, buffer_size: usize) -> anyhow::Result<()> { Ok(()) } + +fn create_progress_bar(file_count: u64) -> ProgressBar { + let progress = ProgressBar::new(file_count); + let parts = vec![ + "{wide_bar}", + "elapsed: {elapsed}", + "files: {pos}/{len}", + "current: {wide_msg}", + "{spinner}", + ]; + progress.set_style(ProgressStyle::default_bar().template(&parts.join("\n"))); + progress +} |