From 8473d0339918600de526a5caee089ae5305699a1 Mon Sep 17 00:00:00 2001 From: "kody.low" Date: Thu, 4 Apr 2024 11:20:24 -0700 Subject: [PATCH] fix: backup_worker --- Cargo.lock | 9 ++++---- gc_fs_backup/Cargo.toml | 5 +++++ gc_fs_backup/src/backup_worker.rs | 37 +++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 gc_fs_backup/src/backup_worker.rs diff --git a/Cargo.lock b/Cargo.lock index 1541149..7d298b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -702,9 +702,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.3" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949626d00e063efc93b6dca932419ceb5432f99769911c0b995f7e884c778813" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", "clap_derive", @@ -724,9 +724,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.3" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90239a040c80f5e14809ca132ddc4176ab33d5e17e49691793296e3fcb34d72f" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -1641,6 +1641,7 @@ name = "gc_fs_backup" version = "0.1.0" dependencies = [ "anyhow", + "clap", "flate2", "google-cloud", "inotify", diff --git a/gc_fs_backup/Cargo.toml b/gc_fs_backup/Cargo.toml index 107bbb1..702269e 100644 --- a/gc_fs_backup/Cargo.toml +++ b/gc_fs_backup/Cargo.toml @@ -5,10 +5,15 @@ edition = "2021" description = "Backup a compressed tarball of a directory to Google Cloud Storage" license = "MIT" +[[bin]] +name = "gc_fs_backup_worker" +path = "src/backup_worker.rs" + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] anyhow = "1.0.81" +clap = "4.5.4" flate2 = "1.0.28" google-cloud = "0.2.1" inotify = "0.10.2" diff --git a/gc_fs_backup/src/backup_worker.rs b/gc_fs_backup/src/backup_worker.rs new file mode 100644 index 0000000..af1d0a3 --- /dev/null +++ b/gc_fs_backup/src/backup_worker.rs @@ -0,0 +1,37 @@ +use std::path::PathBuf; + +use clap::Parser; +use gc_fs_backup::GcFsBackupBuilder; + +#[derive(Parser)] +#[clap(version = "1.0", author = "Kody Low ")] +struct Cli { + /// Sets the database path to backup + #[clap(long, value_name = "DB_PATH", env = "DB_PATH", required = true)] + db_path: PathBuf, + + /// Sets the bucket ID for the backup + #[clap(long, value_name = "BUCKET_ID", env = "BUCKET_ID", required = true)] + bucket_id: String, + + /// Sets the credentials for accessing the storage + #[clap(long, value_name = "CREDENTIAL", env = "CREDENTIAL", required = true)] + credential: String, + + /// Sets the name for the backup + #[clap(long, value_name = "BACKUP_NAME", env = "BACKUP_NAME")] + backup_name: String, +} + +#[tokio::main] +async fn main() { + let cli: Cli = Cli::parse(); + + let backup = GcFsBackupBuilder::new() + .db_path(cli.db_path.into()) + .bucket_id(cli.bucket_id.into()) + .credential(cli.credential.into()) + .backup_name(cli.backup_name.into()) + .build(); + backup.backup_directory_contents().await.unwrap(); +}