@@ -238,14 +238,14 @@ func (opt *mongoOptions) restoreMongoDB(targetRef api_v1beta1.TargetRef) (*resti
238
238
// So, for stand-alone MongoDB and MongoDB ReplicaSet, we don't have to do anything.
239
239
// We only need to update totalHosts field for sharded MongoDB
240
240
241
+ restoreSession , err := opt .stashClient .StashV1beta1 ().RestoreSessions (opt .namespace ).Get (context .TODO (), opt .restoreSessionName , metav1.GetOptions {})
242
+ if err != nil {
243
+ return nil , err
244
+ }
241
245
opt .totalHosts = 1
242
246
// For sharded MongoDB, parameter.ConfigServer will not be empty
243
247
if parameters .ConfigServer != "" {
244
248
opt .totalHosts = len (parameters .ReplicaSets ) + 1 // for each shard there will be one key in parameters.ReplicaSet
245
- restoreSession , err := opt .stashClient .StashV1beta1 ().RestoreSessions (opt .namespace ).Get (context .TODO (), opt .restoreSessionName , metav1.GetOptions {})
246
- if err != nil {
247
- return nil , err
248
- }
249
249
_ , err = stash_cs_util .UpdateRestoreSessionStatus (
250
250
context .TODO (),
251
251
opt .stashClient .StashV1beta1 (),
@@ -326,9 +326,8 @@ func (opt *mongoOptions) restoreMongoDB(targetRef api_v1beta1.TargetRef) (*resti
326
326
Host : hostKey ,
327
327
SourceHost : hostKey ,
328
328
FileName : opt .defaultDumpOptions .FileName ,
329
- Snapshot : opt .defaultDumpOptions . Snapshot ,
329
+ Snapshot : opt .getSnapshotForHost ( hostKey , restoreSession . Spec . Target . Rules ) ,
330
330
}
331
-
332
331
// setup pipe command
333
332
restoreCmd := restic.Command {
334
333
Name : MongoRestoreCMD ,
@@ -578,3 +577,19 @@ func (opt *mongoOptions) getHostRestoreStats(err error) []api_v1beta1.HostRestor
578
577
579
578
return restoreStats
580
579
}
580
+
581
+ func (opt * mongoOptions ) getSnapshotForHost (hostname string , rules []api_v1beta1.Rule ) string {
582
+ var hostSnapshot string
583
+ for _ , rule := range rules {
584
+ if len (rule .TargetHosts ) == 0 || containsString (rule .TargetHosts , hostname ) {
585
+ hostSnapshot = rule .Snapshots [0 ]
586
+ // if rule has empty targetHost then check further rules to see if any other rule with non-empty targetHost matches
587
+ if len (rule .TargetHosts ) == 0 {
588
+ continue
589
+ } else {
590
+ return hostSnapshot
591
+ }
592
+ }
593
+ }
594
+ return hostSnapshot
595
+ }
0 commit comments