@@ -2,6 +2,7 @@ use anyhow::Result;
2
2
use aws_sdk_s3:: Client ;
3
3
use chrono:: NaiveDateTime ;
4
4
use clap:: { Parser , Subcommand } ;
5
+ use std:: path:: PathBuf ;
5
6
6
7
mod replicator_extras;
7
8
use crate :: replicator_extras:: detect_db;
@@ -168,6 +169,12 @@ async fn run() -> Result<()> {
168
169
} => {
169
170
tokio:: fs:: create_dir_all ( & database_dir) . await ?;
170
171
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" ) ;
171
178
}
172
179
Commands :: Verify {
173
180
generation,
@@ -179,15 +186,13 @@ async fn run() -> Result<()> {
179
186
client. restore ( generation, utc_time) . await ?;
180
187
let size = tokio:: fs:: metadata ( & temp) . await ?. len ( ) ;
181
188
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) ;
187
190
let _ = tokio:: fs:: remove_file ( & temp) . await ;
188
- if result != "ok" {
191
+ if let Err ( e) = result {
192
+ println ! ( "Verification failed: {e}" ) ;
189
193
std:: process:: exit ( 1 )
190
194
}
195
+ println ! ( "Verification: ok" ) ;
191
196
}
192
197
Commands :: Rm {
193
198
generation,
@@ -205,6 +210,18 @@ async fn run() -> Result<()> {
205
210
Ok ( ( ) )
206
211
}
207
212
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
+
208
225
#[ tokio:: main]
209
226
async fn main ( ) {
210
227
if let Err ( e) = run ( ) . await {
0 commit comments