diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-03-20 07:52:38 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-03-20 10:53:46 +0200 |
commit | a2bee6568dee4c23ed008e657f38352da4190f24 (patch) | |
tree | 7fb2550a80b71692395155b8c4c4dc7c31f27c77 /src/cmd/backup.rs | |
parent | 873738f0e1dc01f2a75e5e60ae68094b4558ed07 (diff) | |
download | obnam2-a2bee6568dee4c23ed008e657f38352da4190f24.tar.gz |
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
Diffstat (limited to 'src/cmd/backup.rs')
-rw-r--r-- | src/cmd/backup.rs | 23 |
1 files changed, 19 insertions, 4 deletions
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<VersionComponent>, +} 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?, + ) } }; |