@@ -38,7 +38,7 @@ type SMongoDBBackup struct {
3838 BackupType string
3939}
4040
41- func (self * SRegion ) GetMongoDBBackups (id string , start time.Time , end time.Time , pageSize , pageNum int ) ([]SMongoDBBackup , int , error ) {
41+ func (self * SRegion ) GetMongoDBBackups (id string , nodeId string , start time.Time , end time.Time , pageSize , pageNum int ) ([]SMongoDBBackup , int , error ) {
4242 if pageSize < 1 || pageSize > 100 {
4343 pageSize = 100
4444 }
@@ -52,6 +52,9 @@ func (self *SRegion) GetMongoDBBackups(id string, start time.Time, end time.Time
5252 "PageSize" : fmt .Sprintf ("%d" , pageSize ),
5353 "PageNumber" : fmt .Sprintf ("%d" , pageNum ),
5454 }
55+ if len (nodeId ) > 0 {
56+ params ["NodeId" ] = nodeId
57+ }
5558 resp , err := self .mongodbRequest ("DescribeBackups" , params )
5659 if err != nil {
5760 return nil , 0 , errors .Wrapf (err , "DescribeBackups" )
@@ -67,15 +70,29 @@ func (self *SRegion) GetMongoDBBackups(id string, start time.Time, end time.Time
6770
6871func (self * SMongoDB ) GetIBackups () ([]cloudprovider.SMongoDBBackup , error ) {
6972 backups := []SMongoDBBackup {}
70- now := time .Now ().Add (time .Minute * - 1 )
71- for {
72- part , total , err := self .region .GetMongoDBBackups (self .DBInstanceId , self .CreationTime , now , 100 , len (backups )/ 100 )
73- if err != nil {
74- return nil , errors .Wrapf (err , "GetMongoDBBackups" )
73+ err := self .Refresh ()
74+ if err != nil {
75+ return nil , errors .Wrapf (err , "Refresh" )
76+ }
77+ nodeIds := []string {}
78+ if self .DBInstanceType == "sharding" {
79+ for _ , shard := range self .ShardList .ShardAttribute {
80+ nodeIds = append (nodeIds , shard .NodeId )
7581 }
76- backups = append (backups , part ... )
77- if len (backups ) >= total {
78- break
82+ } else {
83+ nodeIds = []string {"" }
84+ }
85+ now := time .Now ().Add (time .Minute * - 1 )
86+ for _ , nodeId := range nodeIds {
87+ for {
88+ part , total , err := self .region .GetMongoDBBackups (self .DBInstanceId , nodeId , self .CreationTime , now , 100 , len (backups )/ 100 )
89+ if err != nil {
90+ return nil , errors .Wrapf (err , "GetMongoDBBackups" )
91+ }
92+ backups = append (backups , part ... )
93+ if len (backups ) >= total {
94+ break
95+ }
7996 }
8097 }
8198 ret := []cloudprovider.SMongoDBBackup {}
0 commit comments