github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/gaussdb/v3/backup/UpdatePolicy.go (about)

     1  package backup
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type UpdatePolicyOpts struct {
    10  	// Instance ID, which is compliant with the UUID format.
    11  	InstanceId   string
    12  	BackupPolicy UpdateBackupPolicy `json:"backup_policy"`
    13  }
    14  
    15  type UpdateBackupPolicy struct {
    16  	// Backup time window. The creation of an automated backup will be triggered during the backup time window. The value cannot be empty.
    17  	// It must be a valid value in the "hh:mm-HH:MM" format. The current time is in the UTC format.
    18  	// The HH value must be 1 greater than the hh value.
    19  	// The values of mm and MM must be the same and must be set to 00. Example value: 21:00-22:00
    20  	StartTime string `json:"start_time"`
    21  	// Backup retention days
    22  	KeepDays int `json:"keep_days"`
    23  	// Backup cycle configuration. Data will be automatically backed up on the selected days every week. Value range:
    24  	// The value is a number separated by commas (,), indicating the days of the week.
    25  	// For example, the value 1,2,3,4 indicates that the backup period is every Monday, Tuesday,Wednesday, and Thursday.
    26  	Period string `json:"period"`
    27  }
    28  
    29  func UpdatePolicy(client *golangsdk.ServiceClient, opts UpdatePolicyOpts) (*UpdatepPolicyResponse, error) {
    30  	// PUT https://{Endpoint}/mysql/v3/{project_id}/instances/{instance_id}/backups/policy/update
    31  	b, err := build.RequestBody(opts.BackupPolicy, "backup_policy")
    32  	if err != nil {
    33  		return nil, err
    34  	}
    35  	raw, err := client.Put(client.ServiceURL("instances", opts.InstanceId, "backups", "policy", "update"), b, nil, &golangsdk.RequestOpts{
    36  		OkCodes: []int{200, 201},
    37  	})
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  
    42  	var res UpdatepPolicyResponse
    43  	err = extract.Into(raw.Body, &res)
    44  	return &res, err
    45  }
    46  
    47  type UpdatepPolicyResponse struct {
    48  	// Backup status. Value:
    49  	// BUILDING: Modification in progress
    50  	// COMPLETED: Modification completed
    51  	// FAILED: Modification failed
    52  	Status string `json:"status"`
    53  	// Instance ID
    54  	InstanceId string `json:"instance_id"`
    55  	// Instance name
    56  	InstanceName string `json:"instance_name"`
    57  }