@@ -226,14 +226,14 @@ func (opt *mongoOptions) restoreMongoDB(targetRef api_v1beta1.TargetRef) (*resti
226
226
// So, for stand-alone MongoDB and MongoDB ReplicaSet, we don't have to do anything.
227
227
// We only need to update totalHosts field for sharded MongoDB
228
228
229
+ restoreSession , err := opt .stashClient .StashV1beta1 ().RestoreSessions (opt .namespace ).Get (context .TODO (), opt .restoreSessionName , metav1.GetOptions {})
230
+ if err != nil {
231
+ return nil , err
232
+ }
229
233
opt .totalHosts = 1
230
234
// For sharded MongoDB, parameter.ConfigServer will not be empty
231
235
if parameters .ConfigServer != "" {
232
236
opt .totalHosts = len (parameters .ReplicaSets ) + 1 // for each shard there will be one key in parameters.ReplicaSet
233
- restoreSession , err := opt .stashClient .StashV1beta1 ().RestoreSessions (opt .namespace ).Get (context .TODO (), opt .restoreSessionName , metav1.GetOptions {})
234
- if err != nil {
235
- return nil , err
236
- }
237
237
_ , err = stash_cs_util .UpdateRestoreSessionStatus (
238
238
context .TODO (),
239
239
opt .stashClient .StashV1beta1 (),
@@ -311,9 +311,8 @@ func (opt *mongoOptions) restoreMongoDB(targetRef api_v1beta1.TargetRef) (*resti
311
311
Host : hostKey ,
312
312
SourceHost : hostKey ,
313
313
FileName : opt .defaultDumpOptions .FileName ,
314
- Snapshot : opt .defaultDumpOptions . Snapshot ,
314
+ Snapshot : opt .getSnapshotForHost ( hostKey , restoreSession . Spec . Target . Rules ) ,
315
315
}
316
-
317
316
// setup pipe command
318
317
restoreCmd := restic.Command {
319
318
Name : MongoRestoreCMD ,
@@ -426,3 +425,19 @@ func (opt *mongoOptions) getHostRestoreStats(err error) []api_v1beta1.HostRestor
426
425
427
426
return restoreStats
428
427
}
428
+
429
+ func (opt * mongoOptions ) getSnapshotForHost (hostname string , rules []api_v1beta1.Rule ) string {
430
+ var hostSnapshot string
431
+ for _ , rule := range rules {
432
+ if len (rule .TargetHosts ) == 0 || containsString (rule .TargetHosts , hostname ) {
433
+ hostSnapshot = rule .Snapshots [0 ]
434
+ // if rule has empty targetHost then check further rules to see if any other rule with non-empty targetHost matches
435
+ if len (rule .TargetHosts ) == 0 {
436
+ continue
437
+ } else {
438
+ return hostSnapshot
439
+ }
440
+ }
441
+ }
442
+ return hostSnapshot
443
+ }
0 commit comments