@@ -26,34 +26,13 @@ async fn main() -> Result<()> {
26
26
let args = Args :: parse ( ) ;
27
27
28
28
match & args. command {
29
- Commands :: Run { config } => run ( config) . await ?,
29
+ Commands :: Run { config } => {
30
+ run ( config) . await ?;
31
+ graceful_shutdown ( ) . await ;
32
+ }
30
33
Commands :: Test { config } => test ( config) . await ?,
31
34
}
32
35
33
- #[ cfg( unix) ]
34
- let terminate = async {
35
- signal:: unix:: signal ( signal:: unix:: SignalKind :: terminate ( ) )
36
- . expect ( "failed to install signal handler" )
37
- . recv ( )
38
- . await ;
39
- tracing:: warn!( "signal terminate received" ) ;
40
- } ;
41
-
42
- #[ cfg( not( unix) ) ]
43
- let terminate = std:: future:: pending :: < ( ) > ( ) ;
44
-
45
- let ctrl_c = async {
46
- signal:: ctrl_c ( )
47
- . await
48
- . expect ( "failed to install signal handler" ) ;
49
- tracing:: warn!( "signal ctrl_c received" ) ;
50
- } ;
51
-
52
- tokio:: select! {
53
- _ = ctrl_c => { } ,
54
- _ = terminate => { } ,
55
- }
56
-
57
36
Ok ( ( ) )
58
37
}
59
38
@@ -77,7 +56,21 @@ async fn run(config_path: &str) -> Result<()> {
77
56
}
78
57
79
58
async fn test ( config_path : & str ) -> Result < ( ) > {
80
- tracing:: warn!( "test unimplemented" ) ;
59
+ // check config file syntax
60
+ let config = read_config ( config_path) . await . map_err ( |e| {
61
+ tracing:: error!( "❌ read config failed at `{}`: {}" , config_path, e) ;
62
+ e
63
+ } ) ?;
64
+ tracing:: info!( "✅ config file syntax is ok" ) ;
65
+
66
+ // check s3 instance
67
+ let s3_op = init_s3 ( & config. s3 ) . await ?;
68
+ s3_op. check ( ) . await . map_err ( |e| {
69
+ tracing:: error!( "❌ connect to s3 service failed: {}" , e) ;
70
+ e
71
+ } ) ?;
72
+ tracing:: info!( "✅ connect to s3 service successfully" ) ;
73
+
81
74
Ok ( ( ) )
82
75
}
83
76
@@ -123,12 +116,14 @@ async fn backup(b: &Backup, s3_oprator: &Operator) -> Result<()> {
123
116
. to_string( ) ,
124
117
] ;
125
118
args. extend ( b. exclude . iter ( ) . map ( |e| format ! ( "--exclude={}" , e) ) ) ;
119
+ args. push ( "-C" . to_string ( ) ) ;
126
120
args. push (
127
121
backup_source
128
122
. to_str ( )
129
123
. ok_or ( anyhow ! ( "failed to convert path to string" ) ) ?
130
124
. to_string ( ) ,
131
125
) ;
126
+ args. push ( "." . to_string ( ) ) ;
132
127
133
128
cmd. args ( args) . kill_on_drop ( true ) ;
134
129
@@ -236,5 +231,31 @@ fn find_remove_files(entries: &[opendal::Entry], name: &str, keep: usize) -> Vec
236
231
to_remove
237
232
}
238
233
234
+ async fn graceful_shutdown ( ) {
235
+ #[ cfg( unix) ]
236
+ let terminate = async {
237
+ signal:: unix:: signal ( signal:: unix:: SignalKind :: terminate ( ) )
238
+ . expect ( "failed to install signal handler" )
239
+ . recv ( )
240
+ . await ;
241
+ tracing:: warn!( "signal terminate received" ) ;
242
+ } ;
243
+
244
+ #[ cfg( not( unix) ) ]
245
+ let terminate = std:: future:: pending :: < ( ) > ( ) ;
246
+
247
+ let ctrl_c = async {
248
+ signal:: ctrl_c ( )
249
+ . await
250
+ . expect ( "failed to install signal handler" ) ;
251
+ tracing:: warn!( "signal ctrl_c received" ) ;
252
+ } ;
253
+
254
+ tokio:: select! {
255
+ _ = ctrl_c => { } ,
256
+ _ = terminate => { } ,
257
+ }
258
+ }
259
+
239
260
#[ cfg( test) ]
240
261
mod tests { }
0 commit comments