@@ -2,6 +2,7 @@ use anyhow::Result;
22use aws_sdk_s3:: Client ;
33use chrono:: NaiveDateTime ;
44use clap:: { Parser , Subcommand } ;
5+ use std:: path:: PathBuf ;
56
67mod replicator_extras;
78use crate :: replicator_extras:: detect_db;
@@ -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+ if let Err ( e) = verify_db ( & db_path) {
174+ println ! ( "Verification failed: {e}" ) ;
175+ std:: process:: exit ( 1 )
176+ }
177+ println ! ( "Verification: ok" ) ;
171178 }
172179 Commands :: Verify {
173180 generation,
@@ -179,15 +186,13 @@ 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 ) ?;
186- println ! ( "Verification: {result}" ) ;
189+ let result = verify_db ( & temp) ;
187190 let _ = tokio:: fs:: remove_file ( & temp) . await ;
188- if result != "ok" {
191+ if let Err ( e) = result {
192+ println ! ( "Verification failed: {e}" ) ;
189193 std:: process:: exit ( 1 )
190194 }
195+ println ! ( "Verification: ok" ) ;
191196 }
192197 Commands :: Rm {
193198 generation,
@@ -205,6 +210,18 @@ async fn run() -> Result<()> {
205210 Ok ( ( ) )
206211}
207212
213+ fn verify_db ( path : & PathBuf ) -> Result < ( ) > {
214+ let conn = rusqlite:: Connection :: open ( path) ?;
215+ let mut stmt = conn. prepare ( "PRAGMA integrity_check" ) ?;
216+ let mut rows = stmt. query ( ( ) ) ?;
217+ let result: String = rows. next ( ) ?. unwrap ( ) . get ( 0 ) ?;
218+ if result == "ok" {
219+ Ok ( ( ) )
220+ } else {
221+ Err ( anyhow:: anyhow!( result. to_string( ) ) )
222+ }
223+ }
224+
208225#[ tokio:: main]
209226async fn main ( ) {
210227 if let Err ( e) = run ( ) . await {
0 commit comments