File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ use tracing::error;
1818
1919use crate :: { rpc_service:: ExternalRpcHandler , AppState } ;
2020
21+ const BACKUP_LOCK_FILE : & str = "/run/dstack-backup.lock" ;
22+
2123pub struct GuestApiHandler {
2224 state : AppState ,
2325}
@@ -43,6 +45,7 @@ impl GuestApiRpc for GuestApiHandler {
4345 device_id : info. device_id ,
4446 app_cert : info. app_cert ,
4547 tcb_info : info. tcb_info ,
48+ backup_in_progress : fs:: metadata ( BACKUP_LOCK_FILE ) . is_ok ( ) ,
4649 } )
4750 }
4851
@@ -112,6 +115,20 @@ impl GuestApiRpc for GuestApiHandler {
112115 async fn list_containers ( self ) -> Result < ListContainersResponse > {
113116 list_containers ( ) . await
114117 }
118+
119+ async fn pre_backup ( self ) -> Result < ( ) > {
120+ fs:: OpenOptions :: new ( )
121+ . create_new ( true )
122+ . write ( true )
123+ . open ( BACKUP_LOCK_FILE )
124+ . context ( "Failed to create backup lock file, there is another backup in progress" ) ?;
125+ Ok ( ( ) )
126+ }
127+
128+ async fn post_backup ( self ) -> Result < ( ) > {
129+ fs:: remove_file ( BACKUP_LOCK_FILE ) . context ( "Failed to remove backup lock file" ) ?;
130+ Ok ( ( ) )
131+ }
115132}
116133
117134pub ( crate ) async fn list_containers ( ) -> Result < ListContainersResponse > {
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ message GuestInfo {
2222 string tcb_info = 5 ;
2323 // Device ID
2424 bytes device_id = 6 ;
25+ // true if backup is in progress
26+ bool backup_in_progress = 7 ;
2527}
2628
2729message IpAddress {
@@ -123,6 +125,8 @@ service GuestApi {
123125 rpc NetworkInfo (google .protobuf .Empty ) returns (NetworkInformation );
124126 rpc ListContainers (google .protobuf .Empty ) returns (ListContainersResponse );
125127 rpc Shutdown (google .protobuf .Empty ) returns (google .protobuf .Empty );
128+ rpc PreBackup (google .protobuf .Empty ) returns (google .protobuf .Empty );
129+ rpc PostBackup (google .protobuf .Empty ) returns (google .protobuf .Empty );
126130}
127131
128132service ProxiedGuestApi {
@@ -131,4 +135,6 @@ service ProxiedGuestApi {
131135 rpc NetworkInfo (Id ) returns (NetworkInformation );
132136 rpc ListContainers (Id ) returns (ListContainersResponse );
133137 rpc Shutdown (Id ) returns (google .protobuf .Empty );
138+ rpc PreBackup (Id ) returns (google .protobuf .Empty );
139+ rpc PostBackup (Id ) returns (google .protobuf .Empty );
134140}
Original file line number Diff line number Diff line change @@ -51,4 +51,12 @@ impl ProxiedGuestApiRpc for GuestApiHandler {
5151 async fn shutdown ( self , request : Id ) -> Result < ( ) > {
5252 self . guest_agent_client ( & request. id ) ?. shutdown ( ) . await
5353 }
54+
55+ async fn pre_backup ( self , request : Id ) -> Result < ( ) > {
56+ self . guest_agent_client ( & request. id ) ?. pre_backup ( ) . await
57+ }
58+
59+ async fn post_backup ( self , request : Id ) -> Result < ( ) > {
60+ self . guest_agent_client ( & request. id ) ?. post_backup ( ) . await
61+ }
5462}
You can’t perform that action at this time.
0 commit comments