@@ -18,6 +18,7 @@ import (
18
18
"crypto/tls"
19
19
"encoding/json"
20
20
"os"
21
+ "os/exec"
21
22
"strings"
22
23
"time"
23
24
@@ -199,6 +200,40 @@ func (h *restoreEBSMetaHelper) doRestore(ctx context.Context, progress glue.Prog
199
200
}
200
201
201
202
if h .cfg .SkipAWS {
203
+ if _ , err := os .Stat ("/usr/local/bin/install-snapshot.sh" ); err == nil {
204
+ log .Info ("start to install snapshots" )
205
+ if err := os .WriteFile ("backupmeta.json" , []byte (h .metaInfo .String ()), 0644 ); err != nil {
206
+ return 0 , errors .Trace (err )
207
+ }
208
+ cmd := exec .Command ("install-snapshot.sh" )
209
+ cmd .Stdout = os .Stdout
210
+ cmd .Stderr = os .Stderr
211
+ if err := cmd .Run (); err != nil {
212
+ log .Warn ("failed to install snapshots" , zap .Error (err ))
213
+ return 0 , errors .Trace (err )
214
+ }
215
+ // Script should write the restore volume ids to /volume-ids.txt.
216
+ // Each line contains: <volume-id> <restore-volume-id>
217
+ data , err := os .ReadFile ("volume-ids.txt" )
218
+ if err != nil {
219
+ return 0 , errors .Trace (err )
220
+ }
221
+ log .Info ("install snapshots finished" , zap .String ("volume-ids" , string (data )))
222
+ volumeIDMap := make (map [string ]string )
223
+ for _ , line := range strings .Split (string (data ), "\n " ) {
224
+ if strings .TrimSpace (line ) == "" {
225
+ continue
226
+ }
227
+ fields := strings .Split (line , " " )
228
+ if len (fields ) != 2 {
229
+ log .Warn ("invalid volume id line" , zap .String ("line" , line ))
230
+ continue
231
+ }
232
+ volumeID , restoreVolumeID := strings .TrimSpace (fields [0 ]), strings .TrimSpace (fields [1 ])
233
+ volumeIDMap [volumeID ] = restoreVolumeID
234
+ }
235
+ h .metaInfo .SetRestoreVolumeIDs (volumeIDMap )
236
+ }
202
237
for i := 0 ; i < int (h .metaInfo .GetStoreCount ()); i ++ {
203
238
progress .Inc ()
204
239
log .Info ("mock: create volume from snapshot finished." , zap .Int ("index" , i ))
0 commit comments