-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathACS::Redis::CreateBackupAndUploadToOSS.json
174 lines (174 loc) · 4.99 KB
/
ACS::Redis::CreateBackupAndUploadToOSS.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"en": "Create redis backup and upload to OSS",
"zh-cn": "创建Redis备份并上传到OSS",
"name-en": "ACS::Redis::CreateBackupAndUploadToOSS",
"name-zh-cn": "创建Redis备份并上传到OSS"
},
"Parameters": {
"regionId": {
"Label": {
"en": "RegionId",
"zh-cn": "地域ID"
},
"Type": "String",
"AssociationProperty": "RegionId"
},
"instanceId": {
"Label": {
"en": "InstanceId",
"zh-cn": "实例ID"
},
"Type": "String",
"AssociationProperty": "ALIYUN::Redis::Instance::InstanceId",
"AssociationPropertyMetadata": {
"RegionId": "${regionId}"
}
},
"OSSRegionId": {
"Label": {
"en": "OSSRegionId",
"zh-cn": "OSS bucket所在地域ID"
},
"Type": "String",
"AssociationProperty": "RegionId"
},
"OSSBucketName": {
"Label": {
"en": "OSSBucketName",
"zh-cn": "OSS Bucket 名称"
},
"Type": "String",
"AssociationProperty": "ALIYUN::OSS::Bucket::BucketName",
"AssociationPropertyMetadata": {
"RegionId": "${OSSRegionId}"
},
"Default": ""
}
},
"Tasks": [
{
"Name": "CreateBackup",
"Action": "ACS::ExecuteApi",
"Description": {
"en": "Create backup",
"zh-cn": "创建Redis备份"
},
"Properties": {
"Service": "r-kvstore",
"API": "CreateBackup",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceId": "{{ instanceId }}"
}
},
"Outputs": {
"BackupJobID": {
"Type": "String",
"ValueSelector": ".BackupJobID"
}
}
},
{
"Name": "WaitForBackupCreated",
"Action": "ACS::WaitFor",
"Description": {
"en": "Wait for backup created",
"zh-cn": "等待备份创建完成"
},
"Retries": 30,
"DelayType": "Exponential",
"Delay": 2,
"BackOff": 2,
"Properties": {
"Service": "r-kvstore",
"API": "DescribeBackupTasks",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceId": "{{ instanceId }}",
"BackupJobId": "{{ CreateBackup.BackupJobID }}"
},
"DesiredValues": [
"Finished"
],
"NotDesiredValues": [],
"StopRetryValues": [],
"PropertySelector": ".BackupJobs[].BackupProgressStatus"
}
},
{
"Name": "GetBackupDownloadUrl",
"Action": "ACS::ExecuteApi",
"Description": {
"en": "Get backup download url",
"zh-cn": "获取备份下载地址"
},
"Properties": {
"Service": "r-kvstore",
"API": "DescribeBackups",
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceId": "{{ instanceId }}",
"BackupJobId": "{{ CreateBackup.BackupJobID }}",
"StartTime": {
"Fn::FormatUTCTime": [
{
"Fn::AddHour": [
"{{ ACS::CurrentUTCTime }}",
-1
]
},
"%Y-%m-%dT%H:%MZ"
]
},
"EndTime": {
"Fn::FormatUTCTime": [
{
"Fn::AddHour": [
"{{ ACS::CurrentUTCTime }}",
1
]
},
"%Y-%m-%dT%H:%MZ"
]
}
}
},
"Outputs": {
"BackupDownloadURL": {
"Type": "List",
"ValueSelector": ".Backups.Backup[].BackupDownloadURL"
}
}
},
{
"Name": "UploadBackupToOSS",
"Action": "ACS::FC::ExecuteScript",
"Description": {
"en": "Upload backup to OSS",
"zh-cn": "上传备份到OSS"
},
"Properties": {
"runtime": "python3.10",
"handler": "index.handler",
"role": "AliyunFcDefaultRole",
"script": "import oss2\nimport requests\n\ndef handler(event, context):\n auth = oss2.StsAuth(context.credentials.access_key_id, context.credentials.access_key_secret, context.credentials.security_token)\n endpoint = 'https://oss-{{OSSRegionId}}.aliyuncs.com'\n bucket = oss2.Bucket(auth, endpoint, '{{OSSBucketName}}')\n unique_identifier = '{{ACS::TaskLoopItem}}'.split('?')[0].split('/')[-1]\n execution_id = '{{ACS::ExecutionId}}'.split('.')[0]\n input = requests.get('{{ACS::TaskLoopItem}}')\n bucket.put_object(f'Backup_{{InstanceId}}/{{ACS::CurrentDate}}/{execution_id}/{unique_identifier}', input)"
},
"Loop": {
"Items": "{{ GetBackupDownloadUrl.BackupDownloadURL }}",
"RateControl": {
"Mode": "Concurrency",
"MaxErrors": 0,
"Concurrency": 20
}
}
}
],
"Outputs": {
"OSSObjectURL": {
"Type": "String",
"Value": "https://oss.console.aliyun.com/bucket/oss-{{OSSRegionId}}/{{OSSBucketName}}/object?path=Backup_{{InstanceId}}/{{ACS::CurrentDate}}/"
}
}
}