incpush 0.1.3

Incrementally back up a big local folder to object storage (GCS/S3/Azure), uploading only changed files and preserving previous versions
Documentation
use anyhow::{Context, Result, bail};
use clap::Parser;

use incpush::backup::{self, Config};
use incpush::cli::Cli;
use incpush::util::human_size;

#[tokio::main(flavor = "current_thread")]
async fn main() {
    if let Err(e) = try_main().await {
        eprintln!("error: {e:#}");
        std::process::exit(1);
    }
}

async fn try_main() -> Result<()> {
    let cli = Cli::parse();

    let source = std::fs::canonicalize(&cli.source)
        .with_context(|| format!("source folder not found: {}", cli.source.display()))?;
    if !source.is_dir() {
        bail!("source must be a directory: {}", source.display());
    }
    if !cli.destination.contains("://") {
        bail!(
            "destination must be a url (e.g. gs://bucket/folder/): {}",
            cli.destination
        );
    }

    let print = cli.print;
    let verb = if print { "will upload" } else { "uploaded" };

    let cfg = Config {
        source,
        dest: cli.destination,
        mode: cli.diff.into(),
        excludes: cli.excludes,
        concurrency: cli.concurrency,
        retries: cli.retries,
        print,
        quiet: cli.quiet,
        reconcile: cli.reconcile,
        no_adopt: cli.no_adopt,
        no_backupignore: cli.no_backupignore,
        snapshot_every: cli.snapshot_every,
        zstd_level: cli.zstd_level,
    };

    let s = backup::run(cfg).await?;

    let mut line = format!(
        "{verb} {}/{} files ({}/{})",
        s.uploaded_files,
        s.total_files,
        human_size(s.uploaded_size),
        human_size(s.total_size),
    );
    if s.adopted > 0 {
        line.push_str(&format!(", {} adopted", s.adopted));
    }
    if s.touched > 0 {
        line.push_str(&format!(", {} unchanged-refresh", s.touched));
    }
    if s.deleted > 0 {
        line.push_str(&format!(", {} deleted", s.deleted));
    }
    if s.snapshot && !print {
        line.push_str(" [snapshot]");
    }
    println!("{line}");
    println!("Done in {:.2?} (run #{})", s.elapsed, s.run);
    Ok(())
}