From 8c7c8a2395d2779cad6e4adff166cafcaae163c8 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Wed, 21 May 2025 19:31:23 -0400 Subject: [PATCH] Handle backup IDs in restore command --- cli-bin/src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cli-bin/src/main.rs b/cli-bin/src/main.rs index b178bff..c2c8246 100644 --- a/cli-bin/src/main.rs +++ b/cli-bin/src/main.rs @@ -11,6 +11,7 @@ mod cli; // sub-command definitions and argument structs /* ── shared modules re-exported from libmarlin ─────────────────── */ use libmarlin::db::take_dirty; use libmarlin::{config, db, logging, scan, utils::determine_scan_root}; +use libmarlin::backup::BackupManager; use anyhow::{Context, Result}; use clap::{CommandFactory, Parser}; @@ -106,8 +107,20 @@ fn main() -> Result<()> { Commands::Restore { backup_path } => { drop(conn); - db::restore(&backup_path, &cfg.db_path) - .with_context(|| format!("Failed to restore DB from {}", backup_path.display()))?; + if backup_path.exists() { + db::restore(&backup_path, &cfg.db_path) + .with_context(|| format!("Failed to restore DB from {}", backup_path.display()))?; + } else { + let backups_dir = cfg.db_path.parent().unwrap().join("backups"); + let manager = BackupManager::new(&cfg.db_path, &backups_dir)?; + let name = backup_path + .file_name() + .and_then(|n| n.to_str()) + .context("invalid backup file name")?; + manager + .restore_from_backup(name) + .with_context(|| format!("Failed to restore DB from {}", backup_path.display()))?; + } println!("Restored DB from {}", backup_path.display()); db::open(&cfg.db_path).with_context(|| { format!("Could not open restored DB at {}", cfg.db_path.display())