forked from
microcosm.blue/microcosm-rs
Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
1use crate::time::Instant;
2use anyhow::Result;
3use clap::Parser;
4use std::path::PathBuf;
5
6#[cfg(feature = "rocks")]
7use rocksdb::backup::{BackupEngine, BackupEngineOptions, RestoreOptions};
8
9use std::time;
10
11/// Aggregate links in the at-mosphere
12#[derive(Parser, Debug)]
13#[command(version, about, long_about = None)]
14struct Args {
15 /// the backup directory to restore *from*
16 #[arg(long)]
17 from_backup_dir: PathBuf,
18 /// the db dir to restore *to*
19 #[arg(long)]
20 to_data_dir: PathBuf,
21}
22
23#[cfg(feature = "rocks")]
24fn main() -> Result<()> {
25 let args = Args::parse();
26
27 eprintln!(
28 "restoring latest rocksdb backup from {:?} to {:?}...",
29 args.from_backup_dir, args.to_data_dir
30 );
31
32 let mut engine = BackupEngine::open(
33 &BackupEngineOptions::new(args.from_backup_dir)?,
34 &rocksdb::Env::new()?,
35 )?;
36
37 let t0 = Instant::now();
38 if let Err(e) = engine.restore_from_latest_backup(
39 &args.to_data_dir,
40 &args.to_data_dir,
41 &RestoreOptions::default(),
42 ) {
43 eprintln!(
44 "restoring from backup failed after {:?}: {e:?}",
45 t0.elapsed()
46 );
47 } else {
48 eprintln!(
49 "success, restored latest from backup after {:?}",
50 t0.elapsed()
51 );
52 }
53
54 eprintln!("bye.");
55 Ok(())
56}