Terminal
Terminal/Skill
Backs up an ECS instance or specific disks to another availability zone using snapshots, leaving the source untouched.
By Alibaba Cloud
Works with
npx skills add aliyun/alibabacloud-aiops-skills --skill alibabacloud-ecs-disaster-recovery-snapshotThis skill provides snapshot-based disaster recovery backup for ECS instances. The original instance and all its resources remain untouched — this is a backup operation, not a migration. It supports two scenarios:
At the start of the workflow, determine which scenario applies based on the user's intent:
| User Intent | Scenario |
|---|---|
| "back up this instance to another AZ" / "create a DR instance" | A |
| "snapshot a disk and attach to another instance" / "mount disk to target instance" | B |
| Ambiguous — ask the user to clarify | Ask |
Once the scenario is determined, follow the corresponding workflow below.
Pre-check: Aliyun CLI >= 3.3.3 required
- Run
aliyun versionto check if CLI is installed and its version.- If CLI is not installed (command not found): inform the user and ask whether to install it. Only after user confirmation, download the installer with
curl -fsSL --connect-timeout 10 --max-time 60 https://aliyuncli.alicdn.com/setup.sh -o /tmp/aliyun_cli_setup.sh, then runbash /tmp/aliyun_cli_setup.shto execute the downloaded script.- If CLI is installed but version < 3.3.3: inform the user of the current version and the minimum requirement, then ask whether to upgrade. Only after user confirmation, run the upgrade command.
- If CLI is installed and version >= 3.3.3: proceed directly, no action needed.
IMPORTANT: Do NOT upgrade Aliyun CLI without explicit user confirmation. Only prompt for upgrade when the version check fails.
Pre-check: Aliyun CLI plugin update required [MUST] run
aliyun configure set --auto-plugin-install trueto enable automatic plugin installation. [MUST] runaliyun plugin updateto ensure that any existing plugins on your local machine are always up-to-date.
Pre-check: Alibaba Cloud Credentials Required
Security Rules:
- NEVER read, echo, or print AK/SK values (e.g.,
echo $ALIBABA_CLOUD_ACCESS_KEY_IDis FORBIDDEN)- NEVER ask the user to input AK/SK directly in the conversation or command line
- NEVER use
aliyun configure setwith literal credential values- NEVER export or set AK/SK as environment variables in commands (e.g.
export ALIBABA_CLOUD_ACCESS_KEY_ID=...is FORBIDDEN). Always usealiyunCLI directly — it uses local credentials automatically.- ONLY use
aliyun configure listto check credential statusaliyun configure listCheck the output for a valid profile (AK, STS, or OAuth identity).
If no valid profile exists, STOP here.
- Obtain credentials from Alibaba Cloud Console
- Configure credentials outside of this session (via
aliyun configurein terminal or environment variables in shell profile)- Return and re-run after
aliyun configure listshows a valid profile
[MUST] All CLI commands MUST follow these standards to avoid parameter errors.
| Rule | Correct | Incorrect |
|---|---|---|
| Command name | describe-instances (kebab-case) | DescribeInstances (PascalCase) |
| User agent | Always include --user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot/{session-id} | Missing user-agent or session-id |
| Region parameter | Use --biz-region-id for commands that support it; use --endpoint only for create-snapshot and attach-disk | --region-id or --RegionId |
| Endpoint | Add --endpoint ecs.<region>.aliyuncs.com when CLI default region differs | Omitting endpoint |
| List parameters | --disk-id val1 val2 (space-separated) | --disk-id.1 val1 --disk-id.2 val2 |
| VSwitch parameter | --vswitch-id | --v-switch-id |
[MUST] CLI User-Agent — Every aliyun CLI command that calls a cloud API must include:
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot/{session-id}
(See Observability section below for session-id generation rules)
See references/ram-policies.md for the full list of required RAM permissions.
[MUST] Permission Failure Handling: When any command or API call fails due to permission errors at any point during execution, follow this process:
- Read
references/ram-policies.mdto get the full list of permissions required by this SKILL- Use
ram-permission-diagnoseskill to guide the user through requesting the necessary permissions- Pause and wait until the user confirms that the required permissions have been granted
Upon loading this skill, generate a random session ID (32-char lowercase hex string) once for the entire session. Use it as {session-id} below.
Rule: Every aliyun CLI command that calls a cloud API MUST include the --user-agent flag.
Local utility commands (e.g. configure, plugin, version) do not support this flag and should be excluded.
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot/{session-id}
Example (assuming session-id is a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6):
aliyun ecs describe-instances --biz-region-id cn-hangzhou --user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot/a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6
Do not skip, alter the format, or omit --user-agent on any aliyun API command invocation.
IMPORTANT: Parameter Confirmation — Before executing any command or API call, ALL user-customizable parameters (e.g., RegionId, instance names, instance IDs, IP addresses, etc.) MUST be confirmed with the user. Do NOT assume or use default values without explicit user approval.
[MUST] Use interactive choice prompts for all user decisions. Use
AskUserQuestiontool to present 2–4 concrete options with short descriptions. Put recommended option first with(Recommended)suffix. Never just "STOP and ask" — always provide clickable options so the user can decide with a single click.
| Parameter Name | Required/Optional | Description | Default Value |
|---|---|---|---|
InstanceId | Required | Source ECS instance ID | N/A |
RegionId | Required | Region where the instance is located | Auto-detected from instance |
TargetZoneId | Required | Target availability zone | N/A |
InstanceName | Optional | Name for the new instance | recovery-<source-instance-name> |
| Parameter Name | Required/Optional | Description | Default Value |
|---|---|---|---|
SourceInstanceId | Required | Source ECS instance ID (disk owner) | N/A |
SourceDiskIds | Required | Specific disk ID(s) to snapshot | All data disks (ask user) |
TargetInstanceId | Required | Target ECS instance ID to attach disks to | N/A |
RegionId | Required | Region where instances are located | Auto-detected from instance |
DiskCategory | Optional | Disk category for new disk(s) | Same as source disk |
Confirm the following inputs with the user (proactively ask if not provided):
recovery-<source-instance-name>)The source instance's RegionId can be auto-detected from instance details — no need to ask the user.
Make two parallel API calls to gather all information:
# Query instance details (spec, security group, VPC, VSwitch)
aliyun ecs describe-instances \
--biz-region-id <region> \
--endpoint ecs.<region>.aliyuncs.com \
--instance-ids '["<instance-id>"]' \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
# Query disk information
aliyun ecs describe-disks \
--biz-region-id <region> \
--endpoint ecs.<region>.aliyuncs.com \
--instance-id <instance-id> \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
Extract and record from the results:
InternetMaxBandwidthOut to the same value as source (must be > 0)InternetMaxBandwidthOut=0 and MUST NOT assign any public IP to the new instance. This is a hard constraint — never enable public IP on the DR instance if the source does not have one./dev/xvda, /dev/xvdb), Type (system/data), Category, Size, and PerformanceLevel (e.g. PL0, PL1 — only applicable to cloud_essd family).
This information is critical for Step 3 (snapshot creation) and Step 6 (instance creation).Determine the snapshot strategy based on the disk count from Step 2:
| Disk Configuration | Strategy |
|---|---|
| System disk + ≥1 data disk (multi-disk) | Use snapshot consistency group (create-snapshot-group) |
| System disk only (single-disk) | Use individual snapshot (create-snapshot) |
Why snapshot consistency group for multi-disk? Snapshot consistency groups guarantee cross-disk crash consistency — all disk snapshots are taken at the same point-in-time. This is critical for applications that span multiple disks (e.g. database with separate data/log disks).
aliyun ecs create-snapshot-group \
--biz-region-id <region> \
--endpoint ecs.<region>.aliyuncs.com \
--instance-id <instance-id> \
--name "SnapGroup_<instance-id>_<date>" \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
Poll with describe-snapshot-groups until Status: accomplished:
aliyun ecs describe-snapshot-groups \
--biz-region-id <region> \
--endpoint ecs.<region>.aliyuncs.com \
--snapshot-group-id <snapshot-group-id> \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
Extract: system snapshot ID (SourceDiskType: system) + data snapshot IDs (SourceDiskType: data).
Important: Snapshot consistency groups support Instant Access — snapshots can be used for
create-imageas soon as group status isaccomplished.
aliyun ecs create-snapshot \
--endpoint ecs.<region>.aliyuncs.com \
--disk-id <system-disk-id> \
--snapshot-name "Snap_<instance-id>_sys_<date>" \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
Poll with describe-snapshots until Available: true AND Progress: 100% AND Status: accomplished.
Failure Handling: See Error Handling Guide for retry strategy, timeout handling, and user interaction patterns.
Important: The system snapshot must be fully ready before proceeding to Step 4 (create-image). Report progress to the user at each poll check.
Create an image containing ALL disk snapshots from the consistency group (system + every data disk).
aliyun ecs create-image \
--biz-region-id <region> \
--endpoint ecs.<region>.aliyuncs.com \
--image-name "Create_from_<instance-id>_<date>" \
--disk-device-mapping DiskType=system SnapshotId=<system-snapshot-id> Size=<system-disk-size> \
--disk-device-mapping DiskType=data SnapshotId=<data-snapshot-id-1> Size=<data-disk-1-size> \
--disk-device-mapping DiskType=data SnapshotId=<data-snapshot-id-2> Size=<data-disk-2-size> \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
Add one
--disk-device-mapping DiskType=data SnapshotId=... Size=...for each data disk. Snapshot IDs come from the consistency group (Step 3 Path A).
aliyun ecs create-image \
--biz-region-id <region> \
--endpoint ecs.<region>.aliyuncs.com \
--image-name "Create_from_<instance-id>_<date>" \
--disk-device-mapping DiskType=system SnapshotId=<system-snapshot-id> Size=<system-disk-size> \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
Image naming convention: Create_from_<instance-id>. Append date suffix _YYYYMMDD if name conflicts.
After creation, confirm Status is Available using describe-images:
aliyun ecs describe-images \
--biz-region-id <region> \
--endpoint ecs.<region>.aliyuncs.com \
--image-id <image-id> \
--status "Creating,Available,UnAvailable" \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
Poll every 60 seconds until Status is Available. Report progress to the user at each check.
Failure Handling: See Error Handling Guide for retry strategy and timeout handling.
Query VSwitch and resource availability in the target AZ:
aliyun ecs describe-vswitches \
--biz-region-id <region> --endpoint ecs.<region>.aliyuncs.com \
--vpc-id <vpc-id> --zone-id <target-az> \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
aliyun ecs describe-available-resource \
--biz-region-id <region> --endpoint ecs.<region>.aliyuncs.com \
--zone-id <target-az> --destination-resource InstanceType \
--instance-type <instance-type> --instance-charge-type PostPaid \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
aliyun ecs describe-available-resource \
--biz-region-id <region> --endpoint ecs.<region>.aliyuncs.com \
--zone-id <target-az> --destination-resource SystemDisk \
--instance-type <instance-type> --instance-charge-type PostPaid \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
Decisions (always use AskUserQuestion):
Create VSwitch (Recommended) / Choose another AZThe image contains all disk snapshots (multi-disk) or system disk snapshot only (single-disk).
While run-instances auto-restores data disk content from the image, it does NOT inherit the source data disk's category or performance level — these MUST be overridden via --data-disk Device=<path> ... parameters.
Critical: The DR instance MUST inherit the source instance's properties:
InternetMaxBandwidthOut to the same value as source (> 0)InternetMaxBandwidthOut=0. NEVER assign a public IP or set bandwidth > 0 when the source instance has no public IP. Violating this rule will expose the DR instance to the internet unexpectedly.CRITICAL:
--system-disk-performance-levelis mandatory for cloud_essd disks. If omitted, the API defaults to PL1.
--data-disk Device=<device-path> Category=<category> Size=<size> PerformanceLevel=<PL> matching the source. The Device= path comes from Step 2 (e.g. /dev/xvdb). Without this, the system defaults to cloud_auto and loses the original performance spec.InstanceChargeType (PrePaid/PostPaid) and InternetChargeType (PayByTraffic/PayByBandwidth) must match source exactly.Disk category decision — always ask the user via AskUserQuestion:
Note the system disk category compatibility in the target AZ. If the original disk category is unsupported,
use AskUserQuestion to present available alternatives as clickable options.
Do NOT silently substitute a disk category.
Instance Naming (MUST follow):
The default instance name format is recovery-<source-instance-name>, where <source-instance-name> is the InstanceName field extracted in Step 2 from describe-instances.
For example, if the source instance name is prod-web-server, the DR instance name MUST be recovery-prod-web-server.
Only override this default if the user explicitly provides a custom name.
Do NOT use instance ID, generic prefixes like dr-backup-, or any other naming pattern.
aliyun ecs run-instances \
--biz-region-id <region> \
--endpoint ecs.<region>.aliyuncs.com \
--zone-id <target-az> \
--image-id <image-id> \
--instance-type <instance-type> \
--security-group-id <sg-id> \
--vswitch-id <target-vswitch-id> \
--system-disk-category <system-disk-category> \
--system-disk-size <system-disk-size> \
--system-disk-performance-level <system-disk-performance-level> \
--data-disk Device=<device-path> Category=<data-disk-category> Size=<data-disk-size> PerformanceLevel=<data-disk-PL> \
--instance-name "recovery-<source-instance-name>" \
--instance-charge-type <instance-charge-type> \
--internet-charge-type <internet-charge-type> \
--internet-max-bandwidth-out <internet-max-bandwidth-out> \
--amount 1 \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
Note:
--data-diskwithDevice=overrides the parameters of that disk in the image — it does NOT create new disks.
Device=/dev/xvdb— overrides the image's data disk parameters (correct). Multiple data disks: use multiple--data-diskflags.SnapshotId=s-xxx— creates an additional disk (incorrect, never use). Do NOT use--data-disk-N-*form; it does not support PL.- For single-disk (system only), omit
--data-disk.
After creation, wait ~15 seconds then confirm Running via describe-instances. Verify each data disk's Category and PerformanceLevel match source via describe-disks.
Failure Handling: See Error Handling Guide for error diagnosis table, retry strategy, and status abnormality handling.
Confirm the following inputs with the user (proactively ask if not provided):
The RegionId can be auto-detected from the source instance details.
aliyun ecs describe-disks \
--biz-region-id <region> --endpoint ecs.<region>.aliyuncs.com \
--instance-id <source-instance-id> \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
aliyun ecs describe-instances \
--biz-region-id <region> --endpoint ecs.<region>.aliyuncs.com \
--instance-ids '["<target-instance-id>"]' \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
Extract: Source disk(s) DiskId/Type/Category/Size; Target instance ZoneId.
For each disk, create an individual snapshot (poll until Status: accomplished + Progress: 100%):
aliyun ecs create-snapshot \
--endpoint ecs.<region>.aliyuncs.com \
--disk-id <disk-id> \
--snapshot-name "Snap_<instance-id>_<disk-type>_<date>" \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
Failure Handling: See Error Handling Guide.
Create new disk(s) in the target instance's AZ. Use AskUserQuestion if disk category is unavailable.
CRITICAL: For cloud_essd disks, always pass
--performance-levelmatching the source disk. If omitted, the API defaults to PL1, which changes the disk's performance specification.
aliyun ecs create-disk \
--biz-region-id <region> --endpoint ecs.<region>.aliyuncs.com \
--zone-id <target-instance-zone> --snapshot-id <snapshot-id> \
--disk-category <disk-category> --size <disk-size> \
--performance-level <performance-level> \
--disk-name "data-from-source" \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
aliyun ecs attach-disk \
--endpoint ecs.<region>.aliyuncs.com \
--disk-id <new-disk-id> --instance-id <target-instance-id> \
--user-agent AlibabaCloud-Agent-Skills/alibabacloud-ecs-disaster-recovery-snapshot
Failure Handling: See Error Handling Guide.
Verify disks show Status: In_use via describe-disks. Remind user that the new disk needs to be mounted on the target instance, but NEVER output system commands (e.g. lsblk, mount, fdisk, mkfs) — you don't know the user's OS or usage scenario.
AskUserQuestion to present clickable options before proceeding.create-snapshot-group to ensure cross-disk crash consistency. Then create a full image with all disk snapshots (DiskType=system + DiskType=data entries). The image provides snapshot data, but --data-disk Device=<path> Category=... Size=... PerformanceLevel=... MUST be passed in run-instances to override each data disk's parameters — without it, data disks default to cloud_auto.create-snapshot + system-disk-only image.--disk-device-mapping with DiskType=system for the system snapshot AND one DiskType=data entry per data disk snapshot. All snapshot IDs come from the consistency group.cloud_essd_entry is not supported in all zones. Verify with describe-available-resource before creation; ask the user which alternative to use.create-snapshot and attach-disk do NOT support --biz-region-id: Use --endpoint ecs.<region>.aliyuncs.com only.Status: accomplished. For individual snapshots, poll until Available: true AND Progress: 100%.create-image which works with InstantAccess snapshots, create-disk requires the snapshot to be fully completed.InternetMaxBandwidthOut=0 — never enable public IP on the DR instance when the source does not have one.run-instances defaults to PL1 for cloud_essd if --system-disk-performance-level is omitted. Always pass the source disk's exact PerformanceLevel (PL0, PL1, PL2, PL3) to prevent unintended spec changes.recovery-<source-instance-name>: Use the InstanceName field from Step 2's describe-instances result, prefixed with recovery-. Do NOT use the instance ID, generic prefixes (e.g. dr-backup-, backup-), or any other naming pattern. Only override if the user explicitly provides a custom name.Upon completion, present a comparison table showing Source Instance vs DR Instance (for Scenario A) or an operation summary table (for Scenario B). Include: Instance IDs, names, zones, types, IP addresses, disk details, image info, and status. For Scenario B, also show target instance's full disk layout table.
| Document | Description |
|---|---|
| CLI Installation Guide | Aliyun CLI installation and configuration instructions |
| Error Handling Guide | Retry strategies, timeout handling, error diagnosis |
| RAM Policies | Required RAM permissions for this skill |
| Related Commands | Full CLI command reference table |
| ECS API Reference | ECS API documentation |
| Aliyun CLI Documentation | CLI usage guide |