天天看點

使用OOS自動删除7天前建立的快照

OOS簡介

Operation Orchestration Service,簡稱OOS,是全面、免費的雲上自動化運維平台,提供運維任務的管理和執行。典型使用場景包括:事件驅動運維,批量操作運維,定時運維任務,跨地域運維等,OOS為重要運維場景提供審批,通知等功能。OOS幫您實作标準化運維任務,進而實踐運維即代碼(Operations as Code)的先進理念。關于OOS更詳細的介紹請參見

什麼是運維編排服務

場景介紹

基于OOS實作自動删除建立于7天前的快照。

操作步驟

1.登陸

OOS控制台 ,找到我的模闆,點選建立模闆。
使用OOS自動删除7天前建立的快照
2.選擇空白模版。
使用OOS自動删除7天前建立的快照
3.複制下文提供的模闆到YAML欄中,輸入模闆名稱(Delete-ExpiredSnapshot),點選建立模闆。
使用OOS自動删除7天前建立的快照
模闆(Delete-ExpiredSnapshot)内容:

FormatVersion: OOS-2019-06-01
Description: ''
Parameters:
  regionId:
    Type: String
    Description:
      en: The id of region.
      zh-cn: 地域ID。
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  force:
    Description:
      en: Specifies whether to forcibly delete the snapshot that has been used to create disks.
      zh-cn: 是否強制删除有磁盤關聯的快照。
    Type: Boolean
    Default: false
  expiredDays:
    Description:
      en: The expired days of snapshot.
      zh-cn: 快照過期天數。
    Type: Number
    Default: 7
  rateControl:
    Description:
      en: Concurrency ratio of task execution.
      zh-cn: 任務執行的并發比率。
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 100%
      Concurrency: 10
Tasks:
  - Name: describeSnapshots
    Action: 'ACS::ExecuteAPI'
    Description: ''
    Properties:
      Service: ECS
      API: DescribeSnapshots
      Parameters:
        RegionId: '{{ regionId }}'
        Filter2Key: CreationEndTime
        Filter2Value:
          'Fn::FormatUTCTime':
            - 'Fn::AddHour':
                - '{{ ACS::CurrentUTCTime }}'
                - "Fn::Eval":
                    - '-{{ expiredDays }}*24'
            - '%Y-%m-%dT00:00Z'
    Outputs:
      snapshotIds:
        Type: List
        ValueSelector: '.Snapshots.Snapshot[].SnapshotId'
  - Name: deleteSnapshots
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Delete the expired snapshots.
      zh-cn: 删除過期快照。
    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 }}'
           

定時執行模版

1.找到定時運維,點選建立,選擇周期性重複執行,設定定時執行的規則。

截圖所示規則:截止規則結束時間,每天0點0分定時執行制指定模闆

使用OOS自動删除7天前建立的快照

2.模闆選擇,選擇上文建立的模闆。參數設定,選擇目标地域,點選确認風險并執行。

使用OOS自動删除7天前建立的快照

3.在執行詳情頁中可以檢視定時執行清單和所操作的資源。

使用OOS自動删除7天前建立的快照