APIs for links and references in the ATmosphere

restore from backup script

+55 -1
+1 -1
constellation/src/bin/main.rs
··· 40 40 /// Start a background task to take backups every N hours 41 41 #[arg(long)] 42 42 backup_interval: Option<u64>, 43 - /// If backup_interval is configured, purge the oldest backup once this many backups are saved 43 + /// Keep at most this many backups purging oldest first, requires --backup-interval 44 44 #[arg(long)] 45 45 max_old_backups: Option<usize>, 46 46 /// Saved jsonl from jetstream to use instead of a live subscription
+54
constellation/src/bin/rocks-restore-from-backup.rs
··· 1 + use crate::time::Instant; 2 + use anyhow::Result; 3 + use clap::Parser; 4 + use std::path::PathBuf; 5 + 6 + use rocksdb::backup::{BackupEngine, BackupEngineOptions, RestoreOptions}; 7 + 8 + use std::time; 9 + 10 + /// Aggregate links in the at-mosphere 11 + #[derive(Parser, Debug)] 12 + #[command(version, about, long_about = None)] 13 + struct Args { 14 + /// the backup directory to restore *from* 15 + #[arg(long)] 16 + from_backup_dir: PathBuf, 17 + /// the db dir to restore *to* 18 + #[arg(long)] 19 + to_data_dir: PathBuf, 20 + } 21 + 22 + fn main() -> Result<()> { 23 + let args = Args::parse(); 24 + 25 + eprintln!( 26 + "restoring latest rocksdb backup from {:?} to {:?}...", 27 + args.from_backup_dir, args.to_data_dir 28 + ); 29 + 30 + let mut engine = BackupEngine::open( 31 + &BackupEngineOptions::new(args.from_backup_dir)?, 32 + &rocksdb::Env::new()?, 33 + )?; 34 + 35 + let t0 = Instant::now(); 36 + if let Err(e) = engine.restore_from_latest_backup( 37 + &args.to_data_dir, 38 + &args.to_data_dir, 39 + &RestoreOptions::default(), 40 + ) { 41 + eprintln!( 42 + "restoring from backup failed after {:?}: {e:?}", 43 + t0.elapsed() 44 + ); 45 + } else { 46 + eprintln!( 47 + "success, restored latest from backup after {:?}", 48 + t0.elapsed() 49 + ); 50 + } 51 + 52 + eprintln!("bye."); 53 + Ok(()) 54 + }