获取rds备份集

 

package main

import (
    "github.com/aliyun/alibaba-cloud-sdk-go/services/rds"
    "encoding/json"
    "fmt"
    "github.com/tidwall/gjson"
    "time"
    "os"
)

func main() {
    var input_date_str string
    inputdate := os.Args[1]  /*外部输入参数*/
    println(inputdate)

    client, err := rds.NewClientWithAccessKey("xxxxxxxxxx", "xxxxxxxxxxxxx", "xxxxxxxxxxxxxxxx")
    input_date_str="20180524"
    input_date,err:=time.ParseInLocation("20060102",input_date_str, time.Local)
    println(input_date.Format("2006-01-02"))
    now_time := time.Now()
    now_date:=now_time.Format("2006-01-02")
    yes_date := now_time.AddDate(0, 0, -4).Format("2006-01-02")
    println(now_date)
    println(yes_date)
    request := rds.CreateDescribeBackupsRequest()
    request.Scheme = "https"
    request.DBInstanceId = "rdsuqu7jququ7jq"
    request.StartTime = yes_date+"T12:00Z"  /*"2019-07-21T12:00Z"*/
    request.EndTime =   now_date + "T12:00Z" /*"2019-07-24T12:00Z"*/
    response, err := client.DescribeBackups(request)
    result,err := json.Marshal(response)
    value0 := gjson.Get(string(result), "Items.Backup.0.BackupDownloadURL")
    println(value0.String())

    /*获取数组个数
    value1 := gjson.Get(string(result), "Items.Backup")
    cc := len(value1.Array())
    println(value1.String())
    println(cc)*/

    if err != nil {
        fmt.Print(err.Error())
    }
}

 

上一篇:如何使用云数据库RDS版


下一篇:什么是云数据库RDS PostgreSQL 版