全部產品
Search
文件中心

CloudOps Orchestration Service:ACS-ECS-ScheduleToCleanUpDisks

更新時間:Dec 18, 2024

模板名稱

ACS-ECS-ScheduleToCleanUpDisks 清理磁碟

立即執行

模板描述

定時清理磁碟,適用於需要定期管理和清理ECS執行個體中的磁碟空間的情境,例如記錄檔的自動清理和臨時檔案的刪除。在配置過程中,使用者需要提供以下必填參數資訊:定時類型(timerTrigger):用於定義清理任務何時觸發,地區ID(regionId):用於指定需要清理磁碟的ECS執行個體所在的地區,目標執行個體(targets):用於定義具體需要操作的ECS執行個體,清理規則(cleanUpInfos):用於指定具體的磁碟清理規則。模板在執行後會返回清理命令的輸出結果清單,方便使用者驗證磁碟清理操作的狀態。

模板類型

自動化

所有者

Alibaba Cloud

輸入參數

參數名稱

描述

類型

是否必填

預設值

約束

timerTrigger

定時類型

Json

targets

目標執行個體

Json

cleanUpInfos

磁碟清理規則

String

字串校正Regex :["‘′\s]+

|

regionId

地區ID

String

{{ ACS::RegionId }}

rateControl

任務執行的並發比率

Json

{‘Mode’: ‘Concurrency’, ‘MaxErrors’: 0, ‘Concurrency’: 10}

OOSAssumeRole

OOS扮演的RAM角色

String

OOSServiceRole

輸出參數

參數名稱

描述

類型

commandOutputs

List

執行此模板需要的權限原則

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:DescribeInstances",
                "ecs:DescribeInvocationResults",
                "ecs:DescribeInvocations",
                "ecs:RunCommand"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

詳情

ACS-ECS-ScheduleToCleanUpDisks詳情

模板內容

FormatVersion: OOS-2019-06-01
Description:
  en: 'Schedule to clean up disks, applicable to scenarios that require periodic management and cleaning of disk space on ECS instances, such as automatic log file cleanup and deletion of temporary files. During configuration, users need to provide the following required parameter information: Timer Trigger (timerTrigger), which defines when the cleanup task is triggered, Region ID (regionId), which specifies the region of the ECS instances where the disks will be cleaned, Target Instances (targets), which defines the specific ECS instances to be operated on, and Cleanup Rule (cleanUpInfos), which specifies the specific disk cleanup rules. Upon execution, the template will return a list of the output results of the cleanup command, enabling users to verify the status of the disk cleanup operations.'
  zh-cn: 定時清理磁碟,適用於需要定期管理和清理ECS執行個體中的磁碟空間的情境,例如記錄檔的自動清理和臨時檔案的刪除。在配置過程中,使用者需要提供以下必填參數資訊:定時類型(timerTrigger):用於定義清理任務何時觸發,地區ID(regionId):用於指定需要清理磁碟的ECS執行個體所在的地區,目標執行個體(targets):用於定義具體需要操作的ECS執行個體,清理規則(cleanUpInfos):用於指定具體的磁碟清理規則。模板在執行後會返回清理命令的輸出結果清單,方便使用者驗證磁碟清理操作的狀態。
  name-en: Cleanup Disks
  name-zh-cn: 清理磁碟
  categories:
    - time_trigger
    - application_manage
    - computenest
Parameters:
  timerTrigger:
    Type: Json
    Label:
      en: TimerTrigger
      zh-cn: 定時類型
    AssociationProperty: ALIYUN::OOS::Component::TimerTrigger
    AssociationPropertyMetadata:
      MinuteInterval: 30
  regionId:
    Type: String
    Label:
      en: RegionId
      zh-cn: 地區ID
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  targets:
    Type: Json
    Label:
      en: TargetInstance
      zh-cn: 目標執行個體
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: 'ALIYUN::ECS::Instance'
      RegionId: regionId
      Status: Running
  cleanUpInfos:
    Description:
      en: 'Format: 3d|/root/log/|*.log,3h|/root/log/|*.access,30m|C:\Users\Administrator\log\|*.log.'
      zh-cn: '格式:3d|/root/log/|*.log,3h|/root/log/|*.access,30m|C:\Users\Administrator\log\|*.log'
    Label:
      en: CleanUpRule
      zh-cn: 磁碟清理規則
    Type: String
    AssociationProperty: ALIYUN::OOS::Component::CleanUpInfo
    AllowedPattern: "^[^\"$`'\\s]+$"
  rateControl:
    Label:
      en: RateControl
      zh-cn: 任務執行的並發比率
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: OOS扮演的RAM角色
    Type: String
    Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: timerTrigger
    Action: 'ACS::TimerTrigger'
    Description:
      en: Triggers a task as scheduled by specifying type and expression
      zh-cn: 通過指定觸發類型和運算式按計劃觸發任務
    Properties:
      Type:
        'Fn::Select':
          - type
          - '{{timerTrigger}}'
      Expression:
        'Fn::Select':
          - expression
          - '{{timerTrigger}}'
      EndDate:
        'Fn::Select':
          - endDate
          - '{{ timerTrigger }}'
      TimeZone:
        'Fn::Select':
          - timeZone
          - '{{ timerTrigger }}'
  - Name: getInstance
    Description:
      en: Views the ECS instances
      zh-cn: 擷取ECS執行個體
    Action: 'ACS::SelectTargets'
    Properties:
      ResourceType: 'ALIYUN::ECS::Instance'
      RegionId: '{{ regionId }}'
      Filters:
        - '{{ targets }}'
    Outputs:
      instanceIds:
        Type: List
        ValueSelector: 'Instances.Instance[].InstanceId'
  - Name: cleanUpDisk
    Action: 'ACS::ECS::CleanUpDisk'
    Description:
      en: Execute cloud assistant command to clean up disk
      zh-cn: 執行雲助手命令清理磁碟
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ ACS::TaskLoopItem }}'
      cleanUpInfos: '{{ cleanUpInfos }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ getInstance.instanceIds }}'
      Outputs:
        commandOutputs:
          AggregateType: Fn::ListJoin
          AggregateField: commandOutput
    Outputs:
      commandOutput:
        Type: String
        ValueSelector: commandOutput
Outputs:
  commandOutputs:
    Type: List
    Value: '{{ cleanUpDisk.commandOutputs }}'
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - timerTrigger
        Label:
          default:
            zh-cn: 清理時間
            en: The time of cleanup disk
      - Parameters:
          - cleanUpInfos
        Label:
          default:
            zh-cn: 設定規則
            en: The rule of cleanup disk
      - Parameters:
          - regionId
          - targets
        Label:
          default:
            zh-cn: 選擇執行個體
            en: Select ECS Instances
      - Parameters:
          - rateControl
          - OOSAssumeRole
        Label:
          default:
            zh-cn: 進階選項
            en: Control Options