github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/rds/v3/backups/RestorePITR.go (about)

     1  package backups
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/rds/v3/instances"
     8  )
     9  
    10  type RestorePITROpts struct {
    11  	// Specifies the restoration information.
    12  	Source Source `json:"source"`
    13  	// Specifies the restoration target.
    14  	Target Target `json:"target"`
    15  }
    16  
    17  type Source struct {
    18  	// Specifies the ID of the backup used to restore data. This parameter must be specified when the backup file is used for restoration.
    19  	BackupID string `json:"backup_id" required:"false"`
    20  	// Specifies the DB instance ID.
    21  	InstanceID string `json:"instance_id" required:"true"`
    22  	// Specifies the time point of data restoration in the UNIX timestamp. The unit is millisecond and the time zone is UTC.
    23  	RestoreTime int64 `json:"restore_time,omitempty"`
    24  	// Specifies the restoration mode. Enumerated values include:
    25  	// backup: indicates using backup files for restoration. In this mode, type is not mandatory and backup_id is mandatory.
    26  	// timestamp: indicates the point-in-time restoration mode. In this mode, type is mandatory and restore_time is no mandatory.
    27  	Type string `json:"type" required:"true"`
    28  }
    29  
    30  type Target struct {
    31  	// Specifies the ID of the DB instance to be restored to.
    32  	InstanceID string `json:"instance_id" required:"true"`
    33  }
    34  
    35  func RestorePITR(c *golangsdk.ServiceClient, opts RestorePITROpts) (string, error) {
    36  	b, err := build.RequestBody(opts, "")
    37  	if err != nil {
    38  		return "", err
    39  	}
    40  
    41  	// POST https://{Endpoint}/v3/{project_id}/instances/recovery
    42  	raw, err := c.Post(c.ServiceURL("instances", "recovery"), b, nil, &golangsdk.RequestOpts{
    43  		OkCodes: []int{200, 201, 202},
    44  	})
    45  	if err != nil {
    46  		return "", err
    47  	}
    48  
    49  	var res instances.JobId
    50  	err = extract.Into(raw.Body, &res)
    51  	return res.JobId, err
    52  }