本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/ec2.EC2.CreateSnapshot方法的典型用法代碼示例。如果您正苦於以下問題:Golang EC2.CreateSnapshot方法的具體用法?Golang EC2.CreateSnapshot怎麽用?Golang EC2.CreateSnapshot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/aws/aws-sdk-go/service/ec2.EC2
的用法示例。
在下文中一共展示了EC2.CreateSnapshot方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createSnapshot
func createSnapshot(svc *ec2.EC2, volumeId string) {
description := descriptionPrefix + time.Now().Local().String()
svc.CreateSnapshot(&ec2.CreateSnapshotInput{
VolumeId: &volumeId,
Description: &description,
})
}
示例2: CreateSnapshot
func CreateSnapshot(v *string, i string, c *ec2.EC2) *string {
params := &ec2.CreateSnapshotInput{
VolumeId: aws.String(*v), // Required
Description: aws.String("Snapshot for :" + i),
DryRun: aws.Bool(false),
}
SnapshotStatus, err := c.CreateSnapshot(params)
if err != nil {
fmt.Println("Error Occured :", err.Error())
os.Exit(1)
}
return SnapshotStatus.SnapshotId
}
示例3: CreateSnapshots
func CreateSnapshots(svc *ec2.EC2) error {
volumes, err := GetBackupVolumes(svc)
if err != nil {
return err
}
if len(volumes) == 0 {
log.Printf("No volumes found matching tags: %s\n", tags)
}
for i, volume := range volumes {
csi := ec2.CreateSnapshotInput{}
csi.VolumeId = volume.VolumeId
volname, _ := getTagValue("Name", volume.Tags)
var description string
if volname == "" {
description = fmt.Sprintf("%s: %s", *tagPrefix, *volume.VolumeId)
} else {
description = fmt.Sprintf("%s: %s (%s)", *tagPrefix, volname, *volume.VolumeId)
}
csi.Description = &description
var err error
var snap *ec2.Snapshot
retries := 0
for {
snap, err = svc.CreateSnapshot(&csi)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
retries++
if retries > MaxSnapshotRetries {
return fmt.Errorf("Maximum snapshot retries reached for volume %s", *volume.VolumeId)
}
if aerr.Code() == "SnapshotCreationPerVolumeRateExceeded" {
sleep := time.Duration(MinSnapshotInterval+math.Pow(float64(5), float64(retries))) * time.Second
log.Printf("SnapshotCreationPerVolumeRateExceeded, sleeping for %f\n", sleep.Seconds())
time.Sleep(sleep)
}
} else {
return err
}
} else {
break
}
}
log.Printf("snapshotting volume, Name: '%s', VolumeId: %s, Size: %d GiB\n", volname, *volume.VolumeId, *volume.Size)
err = CreateSnapshotTags(svc, *snap.SnapshotId, volname, *volume.VolumeId)
if err != nil {
return err
}
// wait before kicking off next snapshot
if i < (len(volumes) - 1) {
time.Sleep(time.Duration(MinSnapshotInterval) * time.Second)
}
}
return nil
}