Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

restore from backup script

Changed files
+55 -1
constellation
+1 -1
constellation/src/bin/main.rs
···
/// Start a background task to take backups every N hours
#[arg(long)]
backup_interval: Option<u64>,
-
/// If backup_interval is configured, purge the oldest backup once this many backups are saved
#[arg(long)]
max_old_backups: Option<usize>,
/// Saved jsonl from jetstream to use instead of a live subscription
···
/// Start a background task to take backups every N hours
#[arg(long)]
backup_interval: Option<u64>,
+
/// Keep at most this many backups purging oldest first, requires --backup-interval
#[arg(long)]
max_old_backups: Option<usize>,
/// Saved jsonl from jetstream to use instead of a live subscription
+54
constellation/src/bin/rocks-restore-from-backup.rs
···
···
+
use crate::time::Instant;
+
use anyhow::Result;
+
use clap::Parser;
+
use std::path::PathBuf;
+
+
use rocksdb::backup::{BackupEngine, BackupEngineOptions, RestoreOptions};
+
+
use std::time;
+
+
/// Aggregate links in the at-mosphere
+
#[derive(Parser, Debug)]
+
#[command(version, about, long_about = None)]
+
struct Args {
+
/// the backup directory to restore *from*
+
#[arg(long)]
+
from_backup_dir: PathBuf,
+
/// the db dir to restore *to*
+
#[arg(long)]
+
to_data_dir: PathBuf,
+
}
+
+
fn main() -> Result<()> {
+
let args = Args::parse();
+
+
eprintln!(
+
"restoring latest rocksdb backup from {:?} to {:?}...",
+
args.from_backup_dir, args.to_data_dir
+
);
+
+
let mut engine = BackupEngine::open(
+
&BackupEngineOptions::new(args.from_backup_dir)?,
+
&rocksdb::Env::new()?,
+
)?;
+
+
let t0 = Instant::now();
+
if let Err(e) = engine.restore_from_latest_backup(
+
&args.to_data_dir,
+
&args.to_data_dir,
+
&RestoreOptions::default(),
+
) {
+
eprintln!(
+
"restoring from backup failed after {:?}: {e:?}",
+
t0.elapsed()
+
);
+
} else {
+
eprintln!(
+
"success, restored latest from backup after {:?}",
+
t0.elapsed()
+
);
+
}
+
+
eprintln!("bye.");
+
Ok(())
+
}