阿里云运维编排实用配置
本文最后更新于 1760 天前,其中的信息可能已经有所发展或是发生改变。

当你使用便宜的的竞价云服务器时,肯定会担心数据问题那么,一下就可以帮你解决问题。
具体为:定时任务-关机-创建镜像-恢复镜像-开机-邮件提醒
后续可能会更新
请关注我的Github:https://github.com/arkylin/Aliyun_OOS_Backup_ECS
此文未经本人允许,禁止转载!
框架如下
Aliyun-OOS-view.png


FormatVersion: OOS-2019-06-01
Description:
  en: Regularly create ECS images.
  zh-cn: 定时创建ECS镜像。
  name-en: Regularly-create-ECS-images
  name-zh-cn: 定时创建ECS镜像
Parameters:
  targets:
    Type: Json
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: 'ALIYUN::ECS::Instance'
  instanceId:
    Description:
      en: The ID of ECS instance.
      zh-cn: ECS实例ID。
    Type: String
  Imagesbasic:
    Description:
      en: The ID of Imagees.
      zh-cn: 基本镜像ID。
    Type: String
  cron:
    Description:
      en: 'The cron expression, refer them here: https://www.alibabacloud.com/help/zh/faq-detail/64769.htm. The minimum interval is one minute.'
      zh-cn: 'cron表达式,详情参考:https://www.alibabacloud.com/help/zh/faq-detail/64769.htm'
    Type: String
    AssociationProperty: Cron
    Default: 0 0 12 ? * *
  endDate:
    Description:
      en: 'The end date of time trigger. Format: yyyy-MM-ddThh:mm:ssZ.'
      zh-cn: '时间触发器结束时间。格式:yyyy-MM-ddThh:mm:ssZ'
    Type: String
    AssociationProperty: DateTime
    AssociationPropertyMetadata:
      Format: 'YYYY-MM-DDThh:mm:ssZ'
  rateControl:
    Description:
      en: Concurrency ratio of task execution.
      zh-cn: 任务执行的并发比率。
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Description:
      en: The RAM role to be assumed by OOS.
      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 Cron expression.
      zh-cn: 通过指定Cron表达式按计划触发任务。
    Properties:
      Type: cron
      Expression: '{{ cron }}'
      EndDate: '{{ endDate }}'

  - Name: getInstance
    Description:
      en: Views the ECS instances.
      zh-cn: 获取ECS实例。
    Action: 'ACS::SelectTargets'
    Properties:
      ResourceType: 'ALIYUN::ECS::Instance'
      Filters:
        - '{{ targets }}'
    Outputs:
      instanceIds:
        Type: List
        ValueSelector: 'Instances.Instance[].InstanceId'

  - Name: StopInstance
    Action: 'ACS::ECS::StopInstance'
    Description: Stops an ECS instance.
    Properties:
      instanceId: '{{ ACS::TaskLoopItem }}'
    OnError: 'ACS::NEXT'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ getInstance.instanceIds }}'

  - Name: createImage
    Action: 'ACS::ECS::CreateImage'
    Description:
      en: Create new image with the specified image name and instance ID.
      zh-cn: 通过指定实例ID和镜像名称创建新的镜像。
    Properties:
      instanceId: '{{ ACS::TaskLoopItem }}'
      imageName: 'Auto_{{ ACS::ExecutionId }}_{{ ACS::TaskLoopItem }}'
    Loop:
      Items: '{{ getInstance.instanceIds }}'
      RateContral: '{{ rateControl }}'
      Outputs:
        imageIds:
          AggregateType: 'Fn::ListJoin'
          AggregateField: imageId
    OnError: ReplaceSystemDiskBasic
    Outputs:
      imageId:
        ValueSelector: imageId
        Type: String

  - Name: ReplaceSystemDisk
    Action: 'ACS::ECS::ReplaceSystemDisk'
    Description: Replaces the system disk of an ECS instance.
    Properties:
      instanceId: '{{ instanceId }}'
      imageId: '{{ ACS::TaskLoopItem }}'
    OnError: ReplaceSystemDiskBasic
    OnSuccess: NotifyByMailYES
    Loop:
      Items: '{{ createImage.ImageIds }}'
      Outputs:
        ImageIds:
          AggregateType: 'Fn::ListJoin'
          AggregateField: ImageId

  - Name: ReplaceSystemDiskBasic
    Action: 'ACS::ECS::ReplaceSystemDisk'
    Description: Replaces the system disk of an ECS instance.
    OnError: NotifyByMailNONO
    OnSuccess: NotifyByMailNO
    Properties:
      instanceId: '{{ instanceId }}'
      imageId: '{{ Imagesbasic }}'

  - Name: NotifyByMailNONO
    Action: ACS::Notify
    Properties:
        NotifyType: Mail
        Mail:
            Host: hwsmtp.exmail.qq.com
            Port: 465
            Username: notify@xyz.blue
            Password: XXXXXXXXXXXXXXX
            Subject: BIG Error Auto Images
            Body: Unable return to Basic
            From: notify@xyz.blue
            To:  [123456789@qq.com,987654321@qq.com]
    OnSuccess: 'ACS::END'
    OnError: 'ACS::END'

  - Name: NotifyByMailNO
    Action: ACS::Notify
    Properties:
        NotifyType: Mail
        Mail:
            Host: hwsmtp.exmail.qq.com
            Port: 465
            Username: notify@xyz.blue
            Password: XXXXXXXXXXXXXXX
            Subject: Error Auto Images
            Body: Return to Basic
            From: notify@xyz.blue
            To:  [123456789@qq.com,987654321@qq.com]
    OnSuccess: 'ACS::END'
    OnError: 'ACS::END'

  - Name: NotifyByMailYES
    Action: ACS::Notify
    Properties:
        NotifyType: Mail
        Mail:
            Host: hwsmtp.exmail.qq.com
            Port: 465
            Username: notify@xyz.blue
            Password: XXXXXXXXXXXXXXX
            Subject: YES Auto Images
            Body: YES TO MAKE
            From: notify@xyz.blue
            To:  [123456789@qq.com,987654321@qq.com
    OnSuccess: 'ACS::END'
    OnError: 'ACS::END'

Outputs:
  imageIds:
    Type: List
    Value: '{{ createImage.imageIds }}'
上一篇
下一篇