本文整理汇总了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
}