Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
verify after db restore is done
Browse files Browse the repository at this point in the history
  • Loading branch information
avinassh committed Oct 9, 2023
1 parent ddc0232 commit 8c8590b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions bottomless-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::PathBuf;

Check failure on line 1 in bottomless-cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Run Rustfmt

Diff in /home/runner/work/sqld/sqld/bottomless-cli/src/main.rs
use anyhow::Result;
use aws_sdk_s3::Client;
use chrono::NaiveDateTime;
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);
let result = verify_db(&db_path).unwrap_or_else(|e| e.to_string());
println!("Verification: {result}");
if result != "ok" {
std::process::exit(1)
}
}
Commands::Verify {
generation,
Expand All @@ -179,10 +186,7 @@ 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)?;
let result = verify_db(&temp).unwrap_or_else(|e| e.to_string());
println!("Verification: {result}");
let _ = tokio::fs::remove_file(&temp).await;
if result != "ok" {
Expand All @@ -205,6 +209,14 @@ async fn run() -> Result<()> {
Ok(())
}

fn verify_db(path: &PathBuf) -> Result<String> {
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)?;
Ok(result)
}

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

0 comments on commit 8c8590b

Please sign in to comment.