diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-03-22 17:10:02 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-03-22 17:10:02 +0000 |
commit | 4a9b26903d48d622f7f2a01eb54eec88e92da868 (patch) | |
tree | 6d1a5f4fa835cd217d256ac3cdd5baec5902a2af /src/cmd/backup.rs | |
parent | 7ae1f33ad0cd0df227e83997268ce2f3540db8d7 (diff) | |
parent | 018fcd28c8dbf84d34cc370496139f678664ca8f (diff) | |
download | obnam2-4a9b26903d48d622f7f2a01eb54eec88e92da868.tar.gz |
Merge branch 'liw/schema-refactor' into 'main'
add backup database schema to evolove; break server database
Closes #194 and #192
See merge request obnam/obnam!222
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..6983de4 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?, + ) } }; |