文档

创建包含快照策略的服务并使用快照回滚服务实例的云盘

本文介绍了如何在一个计算巢服务中创建快照策略并应用于对应的云盘,以及如何利用快照回滚计算巢服务实例的云盘。

背景信息

在创建服务时,经常会出现需要定期为云盘备份数据,以应对因误删、勒索病毒等造成的数据丢失或者应用系统故障的场景。为了应对在需要时能够快速找回云盘数据以保证业务的连续性的需求,阿里云ECS提供了自动快照功能,该功能通过自动快照策略实现。自动快照策略可以在预设的时间点周期性地创建快照,保护系统盘和数据盘的数据。

步骤一:关联资源标签

您可以使用关联资源标签设置功能,实现操作主资源标签或主资源与关联资源建立联系时,关联资源可以自动跟随继承主资源的标签变更,提高运维效率,节省标签管理成本。更多信息,请参见关联资源标签设置

  1. 登录标签控制台

  2. 在左侧导航栏中,选择标签 > 关联资源标签设置

  3. 在管理资源标签设置页中,勾选启用管理资源跟随标签编辑功能,然后单击启用并设置规则

    image.png

  4. 在弹出的界面的云服务器云盘的关联资源处,勾选快照,然后选择全部标签键image.png

  5. 单击确定

步骤二:创建包含快照策略的服务

  1. 登录计算巢控制台

  2. 在左侧导航栏中,选择服务目录 > 我的服务

  3. 单击创建新服务,然后在创建新服务页面中,配置服务信息。

    此次只列举本示例中需要特别配置的内容,更多信息,请参见创建私有部署服务

    1. 模板内容处,填写模板内容。详细信息,请参见模板示例2024-01-24_17-12-10.png

    2. 服务运维(选填)区域的运维处,勾选需要用户授权并选择全部权限。2024-01-24_17-17-20.png

  4. 单击创建任务

    任务创建完成后,发布服务。更多信息,请参见上线服务

步骤三:创建服务实例并利用快照回滚云盘

  1. 创建服务实例。

    更多信息,请参见创建服务实例

  2. 服务实例创建完成后,进入服务实例详情页。

  3. 运维管理页签的应用运维区域,单击2024-01-24_17-46-30.png,然后选择使用快照恢复数据截屏2023-12-26 10.09.49.png

  4. 在弹出的界面中,选择需要回滚的ECS实例ID,需要回滚的云盘ID和需要回滚的快照ID等信息。2024-01-24_17-52-33.png

  5. 单击下一步,然后在确认页签中确认界面确认信息并单击创建

    您可以在界面中查看创建信息。7.png

    创建完成后,您可以单击详情,可进入详情页查看详细信息。image.png

模板示例

本示例模板中包含如何创建快照策略、并将快照策略关联到对应云盘。同时示例中创建的快照策略每天0点,一周七天为云盘创建快照,每个快照保留7天。

ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: 利用ros模板创建快照策略并关联云盘
Parameters:
  PayType:
    Type: String
    Label:
      en: ECS Instance Charge Type
      zh-cn: 付费类型
    Default: PostPaid
    AllowedValues:
      - PostPaid
      - PrePaid
    AssociationProperty: ChargeType
    AssociationPropertyMetadata:
      LocaleKey: InstanceChargeType
  PayPeriodUnit:
    Type: String
    Label:
      en: Pay Period Unit
      zh-cn: 购买资源时长周期
    Default: Month
    AllowedValues:
      - Month
      - Year
    AssociationProperty: PayPeriodUnit
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Not:
            Fn::Equals:
              - ${PayType}
              - PostPaid
  PayPeriod:
    Type: Number
    Label:
      en: Period
      zh-cn: 购买资源时长
    Default: 1
    AllowedValues:
      - 1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
    AssociationProperty: PayPeriod
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Not:
            Fn::Equals:
              - ${PayType}
              - PostPaid
  ZoneId:
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance:ZoneId
    Label:
      en: Zone ID
      zh-cn: 可用区
  VpcId:
    Type: String
    Label:
      en: VPC Id
      zh-cn: 专有网络VPC id
    AssociationProperty: ALIYUN::ECS::VPC::VPCId
  VSwitchId:
    Type: String
    Label:
      en: VSwitch Id
      zh-cn: 交换机ID
    AssociationProperty: ALIYUN::ECS::VSwitch::VSwitchId
    AssociationPropertyMetadata:
      VpcId: ${VpcId}
      ZoneId: ${ZoneId}
  LoginPassword:
    NoEcho: true
    Type: String
    Description:
      en: 'Length 8-32 characters, can contain size letters, Numbers and special symbols, including:! @ # $ % ^ & * ( ) _ + - ='
      zh-cn: 长度8-32个字符,可包含大小字母、数字及特殊符号(包含:!@#$%^&*()_+-=)
    Label:
      en: Instance Password
      zh-cn: 实例密码
    AssociationProperty: ALIYUN::ECS::Instance::Password
    ConstraintDescription:
      en: '8-32 characters, can contain size letters, Numbers and special symbols, including:! @ # $ % ^ & * ( ) _ + - ='
      zh-cn: 8-32个字符,可包含大小字母、数字及特殊符号(包含:!@#$%^&*()_+-=)
    MinLength: 8
    MaxLength: 32
  SecurityGroupId:
    Type: String
    AssociationProperty: ALIYUN::ECS::SecurityGroup::SecurityGroupId
    AssociationPropertyMetadata:
      VpcId: ${VpcId}
    Default: ''
    Description:
      en: Please search the business security group ID starting with(sg-xxx)from console-ECS-Network & Security
      zh-cn: 现有业务安全组的实例ID
    Label:
      en: Business Security Group ID
      zh-cn: 业务安全组ID
  EcsInstanceType:
    Type: String
    Label:
      en: Instance Type
      zh-cn: 跳板机实例类型
    AssociationProperty: ALIYUN::ECS::Instance::InstanceType
    AssociationPropertyMetadata:
      ZoneId: ${ZoneId}
      InstanceChargeType: ${PayType}
    Default: ecs.g6.large
  SystemDiskCategory:
    Type: String
    AllowedValues:
      - cloud_efficiency
      - cloud_ssd
      - cloud_essd
    Label:
      en: System Disk Category
      zh-cn: 系统盘类型
    AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
    AssociationPropertyMetadata:
      LocaleKey: DiskCategory
      InstanceType: ${EcsInstanceType}
    Default: cloud_essd
  SystemDiskSize:
    Default: 40
    Type: Number
    Label:
      zh-cn: 系统盘空间 (GB)
      en: System Disk Space (GB)
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - PayType
          - PayPeriodUnit
          - PayPeriod
        Label:
          default:
            en: PayType Configuration
            zh-cn: 付费类型配置
      - Parameters:
          - ZoneId
          - VpcId
          - VSwitchId
          - SecurityGroupId
          - LoginPassword
        Label:
          en: Basic Configuration
          zh-cn: 基础配置
      - Parameters:
          - EcsInstanceType
          - SystemDiskSize
          - SystemDiskCategory
        Label:
          en: ECS跳板机配置
          zh-cn: ECS跳板机配置
Outputs:
  endpoint:
    Description:
      zh-cn: 对外暴露的公网IP地址
      en: Public IP Addresses
    Value:
      Fn::GetAtt:
        - EcsInstanceJumpBox
        - PrivateIps
Resources:
  DiskSnapshotPolicy:
    Type: ALIYUN::ECS::AutoSnapshotPolicy
    Properties:
      TimePoints:
        - 0
      RepeatWeekdays:
        - 1
        - 2
        - 3
        - 4
        - 5
        - 6
        - 7
      RetentionDays: 7
  EcsInstanceJumpBox:
    Type: ALIYUN::ECS::InstanceGroup
    Properties:
      MaxAmount: 1
      ZoneId:
        Ref: ZoneId
      InstanceChargeType:
        Ref: PayType
      Period:
        Ref: PayPeriod
      InstanceName: jumpbox
      ImageId: centos_7
      InstanceType:
        Ref: EcsInstanceType
      VpcId:
        Ref: VpcId
      VSwitchId:
        Ref: VSwitchId
      AllocatePublicIP: false
      Password:
        Ref: LoginPassword
      SystemDiskSize:
        Ref: SystemDiskSize
      SystemDiskCategory:
        Ref: SystemDiskCategory
      SecurityGroupId:
        Ref: SecurityGroupId
      SystemDiskAutoSnapshotPolicyId:
        Ref: DiskSnapshotPolicy
      DiskMappings:
        - Category:
            Ref: SystemDiskCategory
          AutoSnapshotPolicyId:
            Ref: DiskSnapshotPolicy
          Device: /dev/xvdb
          Size:
            Ref: SystemDiskSize
  • 本页导读 (0)
文档反馈