-
Notifications
You must be signed in to change notification settings - Fork 17
/
ACS-ECS-RestoreDataWithSnapshot.json
375 lines (375 loc) · 11.3 KB
/
ACS-ECS-RestoreDataWithSnapshot.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
{
"FormatVersion": "OOS-2019-06-01",
"Description": {
"en": "Use snapshot to create a temporary cloud disk to restore data",
"zh-cn": "使用快照创建临时云盘恢复数据",
"name-en": "ACS-ECS-RestoreDataWithSnapshot",
"name-zh-cn": "使用快照恢复数据",
"categories": [
"instance_manage"
]
},
"Parameters": {
"regionId": {
"Type": "String",
"Label": {
"en": "RegionId",
"zh-cn": "地域ID"
},
"AssociationProperty": "RegionId"
},
"snapshotId": {
"Type": "String",
"Label": {
"en": "SnapshotId",
"zh-cn": "快照ID"
},
"AssociationProperty": "ALIYUN::ECS::Snapshot::SnapshotId"
},
"instanceId": {
"Type": "String",
"Label": {
"en": "InstanceId",
"zh-cn": "实例ID"
},
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceId",
"AssociationPropertyMetadata": {
"RegionId": "regionId",
"Status": "Running"
}
},
"retainTempDisk": {
"Type": "Boolean",
"Label": {
"en": "RetainTempDisk",
"zh-cn": "是否保留临时云盘"
},
"Description": {
"en": "Whether to retain the temporary cloud disk. If you want to retain the temporary cloud disk, select Yes to use it as a common cloud disk. You can manually unmount and release the cloud disk when it is not needed",
"zh-cn": "是否保留临时云盘,如果您希望保留临时云盘,可以选择“是”,将其作为普通云盘使用,不需要时您可以手动卸载并释放该云盘"
},
"Default": false
},
"workingDir": {
"Type": "String",
"Label": {
"en": "WorkingDir",
"zh-cn": "运行目录"
},
"Description": {
"en": "Root permission is required to execute this script. Linux instances: under the home directory of the administrator (root user): /root. Windows instances: do not support OOS script execution. Manually create a temporary cloud disk to recover data",
"zh-cn": "执行该脚本需要root权限。Linux系统实例默认在管理员(root用户)的home目录下,即/root。Windows系统实例不支持OOS脚本执行,请手动创建临时云盘恢复数据"
},
"Default": "/root"
},
"OOSAssumeRole": {
"Type": "String",
"Label": {
"en": "OOSAssumeRole",
"zh-cn": "OOS扮演的RAM角色"
},
"Default": ""
}
},
"RamRole": "{{ OOSAssumeRole }}",
"Tasks": [
{
"Name": "checkInstanceStatus",
"Action": "ACS::CheckFor",
"Description": {
"en": "Check instance status",
"zh-cn": "检查实例状态"
},
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"DesiredValues": [
"Running"
],
"Parameters": {
"RegionId": "{{ regionId }}",
"InstanceIds": [
"{{ instanceId }} "
]
},
"PropertySelector": "Instances.Instance[].Status"
},
"Outputs": {
"zoneId": {
"Type": "String",
"ValueSelector": "Instances.Instance[].ZoneId"
}
}
},
{
"Name": "createDiskBySnapshot",
"Action": "ACS::ExecuteApi",
"Description": {
"en": "Use the snapshot to create a temporary cloud disk",
"zh-cn": "使用快照创建一块临时云盘"
},
"Properties": {
"Service": "ECS",
"API": "CreateDisk",
"Parameters": {
"RegionId": "{{ regionId }}",
"ZoneId": "{{ checkInstanceStatus.zoneId }}",
"SnapshotId": "{{ snapshotId}}",
"DiskName": "TempDiskFrom-{{ snapshotId }}",
"DiskCategory": "cloud_essd"
}
},
"Outputs": {
"diskId": {
"Type": "String",
"ValueSelector": ".DiskId"
}
}
},
{
"Name": "modifyDiskAttribute",
"Action": "ACS::ExecuteApi",
"Description": {
"en": "Modify temporary cloud disk attributes and release them with the instance",
"zh-cn": "修改临时云盘属性,随实例释放"
},
"Properties": {
"Service": "ECS",
"API": "ModifyDiskAttribute",
"Parameters": {
"DiskId": "{{ createDiskBySnapshot.diskId }}",
"DeleteWithInstance": true
}
}
},
{
"Name": "attachDisk",
"Action": "ACS::ExecuteApi",
"Description": {
"en": "Mount the temporary cloud disk to the ECS instance",
"zh-cn": "将临时云盘挂载到ECS实例上"
},
"Properties": {
"Service": "ECS",
"API": "AttachDisk",
"Parameters": {
"InstanceId": "{{ instanceId }}",
"DiskId": "{{ createDiskBySnapshot.diskId }}"
}
}
},
{
"Name": "waitForDiskStatusInUse",
"Action": "ACS::WaitFor",
"Description": {
"en": "Wait until the cloud disk status changes to In_use",
"zh-cn": "等待云盘状态变为使用中"
},
"Properties": {
"Service": "ECS",
"API": "DescribeDisks",
"Parameters": {
"DiskIds": [
"{{ createDiskBySnapshot.diskId }}"
]
},
"PropertySelector": "Disks.Disk[].Status",
"DesiredValues": [
"In_use"
]
},
"Retries": 15,
"DelayType": "Constant",
"Delay": 1
},
{
"Name": "mountDisk",
"Action": "ACS::ECS::RunCommand",
"Description": {
"en": "Mount the cloud disk in the ECS instance",
"zh-cn": "在ECS实例中挂载云盘"
},
"Properties": {
"commandType": "RunShellScript",
"workingDir": "{{ workingDir }}",
"instanceId": "{{ instanceId }}",
"regionId": "{{ regionId }}",
"commandContent": "echo \"查看磁盘和分区\"\nfdisk -l\nfile_system_by_oos=`blkid | tail -n 1 | awk -F : '{print $1}'`\nfile_system_type=`blkid | tail -n 1 | awk '{print $4}' | awk -F \\\" '{print $2}'`\necho \"文件系统类型:${file_system_type}\"\nif [ ${file_system_type} == \"xfs\" ]; then \n echo \"修改xfs文件系统的UUID\"\n xfs_repair -L ${file_system_by_oos}\n xfs_admin -U generate ${file_system_by_oos}\nelse\n echo \"修改ext2、ext3或ext4文件系统的UUID\"\n e2fsck -y -f ${file_system_by_oos}\n uuidgen | xargs tune2fs ${file_system_by_oos} -U\nfi\nblkid\necho \"配置/etc/fstab文件并挂载分区\"\ncp /etc/fstab /etc/fstab.bakbyoos -n\nmkdir -p /mntbyoos\necho `blkid ${file_system_by_oos} | awk '{print $2}' | sed 's/\\\"//g'` /mntbyoos ${file_system_type} defaults 0 0 >> /etc/fstab\ncat /etc/fstab\nmount ${file_system_by_oos}\necho \"查看结果\"\ndf -h\n",
"windowsPasswordName": "",
"enableParameter": false,
"parameters": {},
"timeout": 600,
"username": ""
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "invocationOutput"
}
}
},
{
"Name": "whetherRetainTempDisk",
"Action": "ACS::Choice",
"Description": {
"en": "Choose next task by retainTempDisk Chosen",
"zh-cn": "根据是否保留临时云盘选择下一步任务"
},
"Properties": {
"DefaultTask": "waitForUserRestoreData",
"Choices": [
{
"When": {
"Fn::Equals": [
true,
"{{ retainTempDisk }}"
]
},
"NextTask": "ACS::END"
}
]
}
},
{
"Name": "waitForUserRestoreData",
"Action": "ACS::Pause",
"Description": {
"en": "Wait for the user to manually restore the required data",
"zh-cn": "等待用户手动恢复所需数据"
}
},
{
"Name": "unmountDisk",
"Action": "ACS::ECS::RunCommand",
"Description": {
"en": "Unmount the cloud disk in the ECS instance",
"zh-cn": "在ECS实例中卸载云盘"
},
"Properties": {
"commandType": "RunShellScript",
"workingDir": "{{ workingDir }}",
"instanceId": "{{ instanceId }}",
"regionId": "{{ regionId }}",
"commandContent": "echo \"查看分区\"\ndf -h\necho \"卸载临时分区并修改/etc/fstab文件\"\nfile_system_by_oos=`df -h | grep /mntbyoos | awk '{print $1}'`\numount ${file_system_by_oos}\nsed -i '/\\/mntbyoos/d' /etc/fstab\nrm -rf /mntbyoos\necho \"查看结果\"\ncat /etc/fstab\ndf -h\n",
"windowsPasswordName": "",
"enableParameter": false,
"parameters": {},
"timeout": 600,
"username": ""
},
"Outputs": {
"commandOutput": {
"Type": "String",
"ValueSelector": "invocationOutput"
}
}
},
{
"Name": "detachDisk",
"Action": "ACS::ExecuteApi",
"Description": {
"en": "Unmount the temporary cloud disk from the ECS instance",
"zh-cn": "从ECS实例上卸载临时云盘"
},
"Properties": {
"Service": "ECS",
"API": "DetachDisk",
"Parameters": {
"InstanceId": "{{ instanceId }}",
"DiskId": "{{ createDiskBySnapshot.diskId }}"
}
}
},
{
"Name": "waitForDiskStatusAvailable",
"Action": "ACS::WaitFor",
"Description": {
"en": "Wait until the cloud disk status changes to Available",
"zh-cn": "等待云盘状态变为待挂载"
},
"Properties": {
"Service": "ECS",
"API": "DescribeDisks",
"Parameters": {
"DiskIds": [
"{{ createDiskBySnapshot.diskId }}"
]
},
"PropertySelector": "Disks.Disk[].Status",
"DesiredValues": [
"Available"
]
},
"Retries": 15,
"DelayType": "Constant",
"Delay": 1
},
{
"Name": "deleteDisk",
"Action": "ACS::ExecuteApi",
"Description": {
"en": "Release the temporary cloud disk",
"zh-cn": "释放临时云盘"
},
"Properties": {
"Service": "ECS",
"API": "DeleteDisk",
"Parameters": {
"DiskId": "{{ createDiskBySnapshot.diskId }}"
}
}
}
],
"Outputs": {
"mountDiskOutputs": {
"Type": "List",
"Value": "{{ mountDisk.commandOutput }}"
},
"unmountDiskOutputs": {
"Type": "List",
"Value": "{{ unmountDisk.commandOutput }}"
}
},
"Metadata": {
"ALIYUN::OOS::Interface": {
"ParameterGroups": [
{
"Parameters": [
"regionId",
"snapshotId",
"instanceId"
],
"Label": {
"default": {
"zh-cn": "选择实例",
"en": "Select Instances"
}
}
},
{
"Parameters": [
"retainTempDisk",
"workingDir"
],
"Label": {
"default": {
"zh-cn": "配置参数",
"en": "Configure Parameters"
}
}
},
{
"Parameters": [
"OOSAssumeRole"
],
"Label": {
"default": {
"zh-cn": "高级选项",
"en": "Control Options"
}
}
}
]
}
}
}