AWS 자동 스냅샷 클라우드포메이션
With Amazon Data Lifecycle Manager, you can manage the lifecycle of your AWS resources. You create lifecycle policies, which are used to automate operations on the specified resources.
Amazon DLM supports Amazon EBS volumes and snapshots. For information about using Amazon DLM with Amazon EBS.
우리는 모든 작업을 코드형 인프라로 수행하기를 원하므로 아래의 cloudformation 템플릿은 여러 보존 기간 옵션(5, 30, 60, 90일)에 대해 4가지 정책을 생성합니다.(필요에 맞게 변경할 수 있음)
AWSTemplateFormatVersion: 2010-09-09
Description: >-
Amazon Data Lifecycle Manager to automate the creation, retention, and deletion of snapshots taken to back up your Amazon EBS volumes
#Metadata:
Resources:
dlmRole:
Type: AWS::IAM::Role
Properties:
Path: /service-role/dlm/
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
-
Effect: "Allow"
Action:
- sts:AssumeRole
Principal:
Service:
- dlm.amazonaws.com
Policies:
- PolicyName: "dlmPolicy"
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- ec2:CreateSnapshot
- ec2:CreateSnapshots
- ec2:DeleteSnapshot
- ec2:DescribeVolumes
- ec2:DescribeInstances
- ec2:DescribeSnapshots
Resource: "*"
- Effect: Allow
Action:
- ec2:CreateTags
Resource: arn:aws:ec2:*::snapshot/*
dlmLifecyclePolicy:
Type: "AWS::DLM::LifecyclePolicy"
Properties:
Description: "DevOps Lifecycle Policy using CloudFormation 5 Day Retention"
State: "ENABLED"
ExecutionRoleArn: !GetAtt dlmRole.Arn
PolicyDetails:
ResourceTypes:
- "INSTANCE"
TargetTags:
-
Key: "DLM-BACKUP"
Value: "YES"
Schedules:
-
Name: "Daily Snapshots 5 Day Retention"
TagsToAdd:
-
Key: "type"
Value: "DailySnapshot"
CreateRule:
Interval: 24
IntervalUnit: "HOURS"
# UTC The time at which the policy runs are scheduled to start. The first policy run starts within an hour after the scheduled time.
Times:
- "02:10"
RetainRule:
Count: 5
CopyTags: true
dlm30LifecyclePolicy:
Type: "AWS::DLM::LifecyclePolicy"
Properties:
Description: "DevOps Lifecycle Policy using CloudFormation 30 Day Retention"
State: "ENABLED"
ExecutionRoleArn: !GetAtt dlmRole.Arn
PolicyDetails:
ResourceTypes:
- "INSTANCE"
TargetTags:
-
Key: "DLM-30BACKUP"
Value: "YES"
Schedules:
-
Name: "Daily Snapshots 30 Day Retention"
TagsToAdd:
-
Key: "type"
Value: "DailySnapshot"
CreateRule:
Interval: 24
IntervalUnit: "HOURS"
# UTC The time at which the policy runs are scheduled to start. The first policy run starts within an hour after the scheduled time.
Times:
- "02:10"
RetainRule:
Count: 30
CopyTags: true
dlm60LifecyclePolicy:
Type: "AWS::DLM::LifecyclePolicy"
Properties:
Description: "DevOps Lifecycle Policy using CloudFormation 60 Day Retention"
State: "ENABLED"
ExecutionRoleArn: !GetAtt dlmRole.Arn
PolicyDetails:
ResourceTypes:
- "INSTANCE"
TargetTags:
-
Key: "DLM-60BACKUP"
Value: "YES"
Schedules:
-
Name: "Daily Snapshots 60 Day Retention"
TagsToAdd:
-
Key: "type"
Value: "DailySnapshot"
CreateRule:
Interval: 24
IntervalUnit: "HOURS"
# UTC The time at which the policy runs are scheduled to start. The first policy run starts within an hour after the scheduled time.
Times:
- "02:10"
RetainRule:
Count: 60
CopyTags: true
dlm90LifecyclePolicy:
Type: "AWS::DLM::LifecyclePolicy"
Properties:
Description: "DevOps Lifecycle Policy using CloudFormation 90 Day Retention"
State: "ENABLED"
ExecutionRoleArn: !GetAtt dlmRole.Arn
PolicyDetails:
ResourceTypes:
- "INSTANCE"
TargetTags:
-
Key: "DLM-90BACKUP"
Value: "YES"
Schedules:
-
Name: "Daily Snapshots 90 Day Retention"
TagsToAdd:
-
Key: "type"
Value: "DailySnapshot"
CreateRule:
Interval: 24
IntervalUnit: "HOURS"
# UTC The time at which the policy runs are scheduled to start. The first policy run starts within an hour after the scheduled time.
Times:
- "02:10"
RetainRule:
Count: 90
CopyTags: true
스택이 배포되면 관련 태그(대소문자 구분)로 스냅샷을 자동화하려는 인스턴스에 태그를 지정할 수 있습니다. 각 정책을 처음 실행할 때 스냅샷 생성, 두 번째 실행 시 자체 수정
Reference
이 문제에 관하여(AWS 자동 스냅샷 클라우드포메이션), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/paulmicheli/aws-automated-snapshot-cloudformation-1g6c텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)