From a2bee6568dee4c23ed008e657f38352da4190f24 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 20 Mar 2022 07:52:38 +0200 Subject: feat: allow user to choose backup schema version for new backups The way this is currently implemented resulted in a lot of code duplication in src/generation.rs. This should be refactored later. My first attempt to do it by adding a trait for a schema variant failed. Sponsored-by: author --- src/cmd/backup.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/cmd/backup.rs') diff --git a/src/cmd/backup.rs b/src/cmd/backup.rs index dae9811..51d0329 100644 --- a/src/cmd/backup.rs +++ b/src/cmd/backup.rs @@ -3,9 +3,10 @@ use crate::backup_run::BackupRun; use crate::client::BackupClient; use crate::config::ClientConfig; -use crate::dbgen::FileId; +use crate::dbgen::{schema_version, FileId, DEFAULT_SCHEMA_MAJOR}; use crate::error::ObnamError; use crate::generation::GenId; +use crate::schema::VersionComponent; use log::info; use std::time::SystemTime; @@ -15,7 +16,11 @@ use tokio::runtime::Runtime; /// Make a backup. #[derive(Debug, StructOpt)] -pub struct Backup {} +pub struct Backup { + /// Backup schema major version. + #[structopt(long)] + backup_version: Option, +} impl Backup { /// Run the command. @@ -27,6 +32,10 @@ impl Backup { async fn run_async(&self, config: &ClientConfig) -> Result<(), ObnamError> { let runtime = SystemTime::now(); + let major = self.backup_version.or(Some(DEFAULT_SCHEMA_MAJOR)).unwrap(); + let schema = schema_version(major)?; + eprintln!("backup: schema: {schema}"); + let client = BackupClient::new(config)?; let genlist = client.list_generations().await?; @@ -39,13 +48,19 @@ impl Backup { info!("fresh backup without a previous generation"); let mut run = BackupRun::initial(config, &client)?; let old = run.start(None, &oldtemp).await?; - (false, run.backup_roots(config, &old, &newtemp).await?) + ( + false, + run.backup_roots(config, &old, &newtemp, schema).await?, + ) } Ok(old_id) => { info!("incremental backup based on {}", old_id); let mut run = BackupRun::incremental(config, &client)?; let old = run.start(Some(&old_id), &oldtemp).await?; - (true, run.backup_roots(config, &old, &newtemp).await?) + ( + true, + run.backup_roots(config, &old, &newtemp, schema).await?, + ) } }; -- cgit v1.2.1 From 2938409cff80d66b4b9f672ab48d2d93822c4aa2 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sun, 20 Mar 2022 07:53:06 +0200 Subject: feat: add subcommands inspect, list-backup-versions Sponsored-by: author --- src/cmd/backup.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cmd/backup.rs') diff --git a/src/cmd/backup.rs b/src/cmd/backup.rs index 51d0329..6983de4 100644 --- a/src/cmd/backup.rs +++ b/src/cmd/backup.rs @@ -34,7 +34,7 @@ impl Backup { let major = self.backup_version.or(Some(DEFAULT_SCHEMA_MAJOR)).unwrap(); let schema = schema_version(major)?; - eprintln!("backup: schema: {schema}"); + eprintln!("backup: schema: {}", schema); let client = BackupClient::new(config)?; let genlist = client.list_generations().await?; -- cgit v1.2.1