Skip to content

Commit 0be8b56

Browse files
authored
Merge pull request #1393 from ioito/hotfix/qx-aliyun-mongodb-backup
fix(aliyun): mogodb node backup
2 parents 0e3f847 + 4b5313d commit 0be8b56

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

pkg/multicloud/aliyun/mongodb_backup.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6871
func (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{}

pkg/multicloud/aliyun/shell/mongodb.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ func init() {
6666

6767
type MongoDBBackupListOptions struct {
6868
ID string
69+
NodeId string
6970
START time.Time
7071
END time.Time
7172
PageSize int
7273
PageNumber int
7374
}
7475

7576
shellutils.R(&MongoDBBackupListOptions{}, "mongodb-backup-list", "List mongodb backups", func(cli *aliyun.SRegion, args *MongoDBBackupListOptions) error {
76-
backups, _, err := cli.GetMongoDBBackups(args.ID, args.START, args.END, args.PageSize, args.PageNumber)
77+
backups, _, err := cli.GetMongoDBBackups(args.ID, args.NodeId, args.START, args.END, args.PageSize, args.PageNumber)
7778
if err != nil {
7879
return err
7980
}

0 commit comments

Comments
 (0)