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

Commit 8c8590b

Browse files
committed
verify after db restore is done
1 parent ddc0232 commit 8c8590b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

bottomless-cli/src/main.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::path::PathBuf;
12
use anyhow::Result;
23
use aws_sdk_s3::Client;
34
use chrono::NaiveDateTime;
@@ -168,6 +169,12 @@ async fn run() -> Result<()> {
168169
} => {
169170
tokio::fs::create_dir_all(&database_dir).await?;
170171
client.restore(generation, utc_time).await?;
172+
let db_path = PathBuf::from(&database);
173+
let result = verify_db(&db_path).unwrap_or_else(|e| e.to_string());
174+
println!("Verification: {result}");
175+
if result != "ok" {
176+
std::process::exit(1)
177+
}
171178
}
172179
Commands::Verify {
173180
generation,
@@ -179,10 +186,7 @@ async fn run() -> Result<()> {
179186
client.restore(generation, utc_time).await?;
180187
let size = tokio::fs::metadata(&temp).await?.len();
181188
println!("Snapshot size: {size}");
182-
let conn = rusqlite::Connection::open(&temp)?;
183-
let mut stmt = conn.prepare("PRAGMA integrity_check")?;
184-
let mut rows = stmt.query(())?;
185-
let result: String = rows.next()?.unwrap().get(0)?;
189+
let result = verify_db(&temp).unwrap_or_else(|e| e.to_string());
186190
println!("Verification: {result}");
187191
let _ = tokio::fs::remove_file(&temp).await;
188192
if result != "ok" {
@@ -205,6 +209,14 @@ async fn run() -> Result<()> {
205209
Ok(())
206210
}
207211

212+
fn verify_db(path: &PathBuf) -> Result<String> {
213+
let conn = rusqlite::Connection::open(path)?;
214+
let mut stmt = conn.prepare("PRAGMA integrity_check")?;
215+
let mut rows = stmt.query(())?;
216+
let result: String = rows.next()?.unwrap().get(0)?;
217+
Ok(result)
218+
}
219+
208220
#[tokio::main]
209221
async fn main() {
210222
if let Err(e) = run().await {

0 commit comments

Comments
 (0)