すべてのプロダクト
Search
ドキュメントセンター

CloudOps Orchestration Service:期限切れのスナップショットの一括削除

最終更新日:Jan 17, 2025

テンプレート名

ACS-ECS-BulkyDeleteExpiredSnapshot

今すぐ実行

テンプレートの説明

期限切れのスナップショットを複数同時に削除します。

テンプレートの種類

自動化

所有者

Alibaba Cloud

入力パラメーター

パラメーター

説明

種類

必須

デフォルト値

制限

expiredDays

スナップショットの期限が切れてから経過した日数。

数値

はい

regionId

リージョン ID。

文字列

いいえ

{{ ACS::RegionId }}

force

スナップショットを強制的に削除するかどうかを指定します。

ブール値

いいえ

False

snapshotName

スナップショットをフィルタリングするために使用される名前フィールド。

文字列

いいえ

tags

スナップショットのタグ。

JSON

いいえ

[]

rateControl

レート制御設定。

JSON

いいえ

{'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10}

OOSAssumeRole

CloudOps Orchestration Service ( OOS ) がアシュームする Resource Access Management ( RAM ) ロール。

文字列

いいえ

""

出力パラメーター

パラメーター

説明

種類

deletedSnapshotIds

リスト

テンプレートを実行するために必要な権限ポリシー

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:DeleteSnapshot",
                "ecs:DescribeSnapshots"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

参照

詳細については、GitHub の ACS-ECS-BulkyDeleteExpiredSnapshot.yml をご参照ください。

テンプレートコンテンツ

FormatVersion: OOS-2019-06-01
Description:
  en: Bulky delete expired snapshot
  zh-cn: the description in Chinese
  name-en: ACS-ECS-BulkyDeleteExpiredSnapshot
  zh-cn: the description in Chinese
  categories:
    - data_backup
Parameters:
  regionId:
    Label:
      en: RegionId
      zh-cn: the description in Chinese
    Type: String
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  force:
    Label:
      en: Forced deletion of Snapshot
      zh-cn: the description in Chinese
    Type: Boolean
    Default: false
  expiredDays:
    Label:
      en: Snapshot Expiration Days
      zh-cn: the description in Chinese
    Type: Number
  snapshotName:
    Label:
      en: Name Field Used To Filter Snapshot
      zh-cn: the description in Chinese
    Type: String
    Default: " "
  tags:
    Label:
      en: Snapshot Tags
      zh-cn: the description in Chinese
    Type: Json
    AssociationProperty: Tags
    AssociationPropertyMetadata:
      ShowSystem: false
    Default: [ ]
  rateControl:
    Label:
      en: Rate Control
      zh-cn: the description in Chinese
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: the description in Chinese
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: describeSnapshots
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Get the snapshots
      zh-cn: the description in Chinese
    Properties:
      Service: ECS
      API: DescribeSnapshots
      Parameters:
        RegionId: '{{ regionId }}'
        Tags: '{{ tags }}'
        Filter2Key: CreationEndTime
        Filter2Value:
          'Fn::FormatUTCTime':
            - 'Fn::AddHour':
                - '{{ ACS::CurrentUTCTime }}'
                - "Fn::Eval":
                    - '-{{ expiredDays }}*24'
            - '%Y-%m-%dT00:00Z'
    Outputs:
      snapshotIds:
        Type: List
        ValueSelector: '.Snapshots.Snapshot[] | select( .SnapshotName | test("{{snapshotName}}")) | .SnapshotId'
  - Name: deleteSnapshots
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Delete the snapshots
      zh-cn: the description in Chinese
    Properties:
      Service: ECS
      API: DeleteSnapshot
      Parameters:
        RegionId: '{{ regionId }}'
        SnapshotId: '{{ ACS::TaskLoopItem }}'
        Force: '{{ force }}'
    Loop:
      Items: '{{ describeSnapshots.snapshotIds }}'
      RateControl: '{{ rateControl }}'
Outputs:
  deletedSnapshotIds:
    Type: List
    Value: '{{ describeSnapshots.snapshotIds }}'
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - regionId
          - expiredDays
          - snapshotName
          - tags
          - force
        Label:
          default:
            zh-cn: the description in Chinese
            en: Configure Parameters
      - Parameters:
          - rateControl
          - OOSAssumeRole
        Label:
          default:
            zh-cn: the description in Chinese
            en: Control Options