Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions bottomless-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::Result;
use aws_sdk_s3::Client;
use chrono::NaiveDateTime;
use clap::{Parser, Subcommand};
use std::path::PathBuf;

mod replicator_extras;
use crate::replicator_extras::detect_db;
Expand Down Expand Up @@ -168,6 +169,12 @@ async fn run() -> Result<()> {
} => {
tokio::fs::create_dir_all(&database_dir).await?;
client.restore(generation, utc_time).await?;
let db_path = PathBuf::from(&database);
if let Err(e) = verify_db(&db_path) {
println!("Verification failed: {e}");
std::process::exit(1)
}
println!("Verification: ok");
}
Commands::Verify {
generation,
Expand All @@ -179,15 +186,13 @@ async fn run() -> Result<()> {
client.restore(generation, utc_time).await?;
let size = tokio::fs::metadata(&temp).await?.len();
println!("Snapshot size: {size}");
let conn = rusqlite::Connection::open(&temp)?;
let mut stmt = conn.prepare("PRAGMA integrity_check")?;
let mut rows = stmt.query(())?;
let result: String = rows.next()?.unwrap().get(0)?;
println!("Verification: {result}");
let result = verify_db(&temp);
let _ = tokio::fs::remove_file(&temp).await;
if result != "ok" {
if let Err(e) = result {
println!("Verification failed: {e}");
std::process::exit(1)
}
println!("Verification: ok");
}
Commands::Rm {
generation,
Expand All @@ -205,6 +210,18 @@ async fn run() -> Result<()> {
Ok(())
}

fn verify_db(path: &PathBuf) -> Result<()> {
let conn = rusqlite::Connection::open(path)?;
let mut stmt = conn.prepare("PRAGMA integrity_check")?;
let mut rows = stmt.query(())?;
let result: String = rows.next()?.unwrap().get(0)?;
if result == "ok" {
Ok(())
} else {
Err(anyhow::anyhow!(result.to_string()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Err(anyhow::anyhow!(result.to_string()))
anyhow::bail!("{result}")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for a followup

}
}

#[tokio::main]
async fn main() {
if let Err(e) = run().await {
Expand Down