1+ use std:: path:: PathBuf ;
12use anyhow:: Result ;
23use aws_sdk_s3:: Client ;
34use 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]
209221async fn main ( ) {
210222 if let Err ( e) = run ( ) . await {
0 commit comments