All Products
Search
Document Center

CloudOps Orchestration Service:ACS-ECS-ScheduleToCleanUpDisks

Last Updated:Dec 23, 2025

Template name

ACS-ECS-ScheduleToCleanUpDisks: Cleans up disks

Execute Now

Template description

This template schedules disk cleanup tasks. It is useful for scenarios that require periodic management and cleanup of disk space on Elastic Compute Service (ECS) instances, such as automatic log file cleanup and temporary file deletion. When you use this template, you must specify a timer trigger (timerTrigger), a region ID (regionId), the target instances (targets), and the cleanup rules (cleanUpInfos). After the template is executed, it returns the output from the cleanup command. You can use this output to verify the status of the disk cleanup operations.

Template type

Automated

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default value

Limit

timerTrigger

The type of the scheduled task.

Json

Yes

targets

Target instance

Json

Yes

cleanUpInfos

The rule for cleaning up data in disks.

String

Yes

String validation regular expression: ^["$`'\s]+$

regionId

The region ID.

String

No

{{ ACS::RegionId }}

rateControl

Task execution concurrency

Json

No

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

OOSAssumeRole

The Resource Access Management (RAM) role that is assumed by CloudOps Orchestration Service (OOS).

String

No

OOSServiceRole

Output parameters

Parameter

Description

Type

commandOutputs

List

Permission policy that is required to execute the template

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

Details

For more information, see ACS-ECS-ScheduleToCleanUpDisks.yml at GitHub.

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: 'Schedules disk cleanup tasks. This template is useful for scenarios that require periodic management and cleanup of disk space on ECS instances, such as automatic log file cleanup and temporary file deletion. During configuration, provide the following required parameters: a timer trigger (timerTrigger) to define when the cleanup task runs, a region ID (regionId) to specify the region of the target ECS instances, target instances (targets) to define the specific ECS instances to operate on, and cleanup rules (cleanUpInfos) to specify the disk cleanup rules. After execution, the template returns a list of output from the cleanup command. This lets you verify the status of the disk cleanup operations.'
  zh-cn: Schedules disk cleanup tasks. This template is useful for scenarios that require periodic management and cleanup of disk space on ECS instances, such as automatic log file cleanup and temporary file deletion. During configuration, provide the following required parameters: a timer trigger (timerTrigger) to define when the cleanup task runs, a region ID (regionId) to specify the region of the target ECS instances, target instances (targets) to define the specific ECS instances to operate on, and cleanup rules (cleanUpInfos) to specify the disk cleanup rules. After execution, the template returns a list of output from the cleanup command. This lets you verify the status of the disk cleanup operations.
  name-en: Clean up disks
  name-zh-cn: Clean up disks
  categories:
    - time_trigger
    - application_manage
    - computenest
Parameters:
  timerTrigger:
    Type: Json
    Label:
      en: Timer trigger
      zh-cn: Timer trigger
    AssociationProperty: ALIYUN::OOS::Component::TimerTrigger
    AssociationPropertyMetadata:
      MinuteInterval: 30
  regionId:
    Type: String
    Label:
      en: Region ID
      zh-cn: Region ID
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  targets:
    Type: Json
    Label:
      en: Target instance
      zh-cn: Target instance
    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: 'Format: 3d|/root/log/|*.log,3h|/root/log/|*.access,30m|C:\Users\Administrator\log\|*.log'
    Label:
      en: Cleanup rule
      zh-cn: Cleanup rule
    Type: String
    AssociationProperty: ALIYUN::OOS::Component::CleanUpInfo
    AllowedPattern: "^[^\"$`'\s]+$"
  rateControl:
    Label:
      en: Rate control
      zh-cn: Task execution concurrency rate
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: RAM role assumed by OOS
    Type: String
    Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: timerTrigger
    Action: 'ACS::TimerTrigger'
    Description:
      en: Triggers a task as scheduled by specifying a type and expression.
      zh-cn: Triggers the task based on the specified trigger type and expression.
    Properties:
      Type:
        'Fn::Select':
          - type
          - '{{timerTrigger}}'
      Expression:
        'Fn::Select':
          - expression
          - '{{timerTrigger}}'
      StartDate:
        'Fn::Select':
          - startDate
          - '{{ timerTrigger }}'
      EndDate:
        'Fn::Select':
          - endDate
          - '{{ timerTrigger }}'
      TimeZone:
        'Fn::Select':
          - timeZone
          - '{{ timerTrigger }}'
  - Name: getInstance
    Description:
      en: Views the ECS instances.
      zh-cn: Gets the ECS instances.
    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: Runs a Cloud Assistant command to clean up the disk.
      zh-cn: Runs a Cloud Assistant command to clean up the disk.
    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: Cleanup time
            en: Cleanup time
      - Parameters:
          - cleanUpInfos
        Label:
          default:
            zh-cn: Rule settings
            en: Rule settings
      - Parameters:
          - regionId
          - targets
        Label:
          default:
            zh-cn: Instance selection
            en: Instance selection
      - Parameters:
          - rateControl
          - OOSAssumeRole
        Label:
          default:
            zh-cn: Advanced options
            en: Advanced options