當前位置: 首頁>>代碼示例>>Golang>>正文


Golang EC2.CreateSnapshot方法代碼示例

本文整理匯總了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,
	})
}
開發者ID:csimsek,項目名稱:aws-autosnapshots-go,代碼行數:7,代碼來源:aws-autosnapshots.go

示例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
}
開發者ID:kumarsarath588,項目名稱:Golang,代碼行數:13,代碼來源:main.go

示例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
}
開發者ID:porjo,項目名稱:auto-snapshot,代碼行數:61,代碼來源:main.go


注:本文中的github.com/aws/aws-sdk-go/service/ec2.EC2.CreateSnapshot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。