environment-management

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Environment Management with Acquia CLI

使用Acquia CLI进行环境管理

Use when:
  • Creating or deleting Continuous Delivery Environments (CDEs)
  • Making one environment identical to another (mirroring)
  • Copying cron tasks between environments
  • Installing SSL certificates
  • Listing or inspecting environments
  • Deploying code to an environment

适用场景:
  • 创建或删除持续交付环境(CDE)
  • 使一个环境与另一个环境完全一致(镜像)
  • 在环境之间复制定时任务(cron)
  • 安装SSL证书
  • 列出或查看环境信息
  • 向环境部署代码

List Environments

列出环境

bash
acli api:applications:environment-list
Shows all environments for an application (prod, staging, dev, and any CDEs).

bash
acli api:applications:environment-list
显示某个应用的所有环境(生产环境、预发布环境、开发环境以及所有CDE)。

Get Environment Details

获取环境详情

bash
acli env:info
Shows PHP version, database, last deployment, URLs, and status for the selected environment.

bash
acli env:info
显示所选环境的PHP版本、数据库信息、上次部署记录、URL以及状态。

Create a Continuous Delivery Environment (CDE)

创建持续交付环境(CDE)

CDEs are on-demand environments — useful for testing feature branches before merging.
bash
acli env:create "My Feature Branch" feature/my-branch
Arguments:
  • label
    (required) — Human-readable name for the new environment
  • branch
    (optional) — The git branch to deploy; prompts if omitted
bash
undefined
CDE是按需创建的环境——非常适合在合并代码前测试功能分支。
bash
acli env:create "My Feature Branch" feature/my-branch
参数:
  • label
    (必填)——新环境的可读名称
  • branch
    (可选)——要部署的Git分支;若省略则会提示输入
bash
undefined

Interactive (prompts for branch)

交互式(提示输入分支)

acli env:create "QA Review"
acli env:create "QA Review"

Non-interactive

非交互式

acli env:create "Sprint 42 Demo" release/sprint-42

---
acli env:create "Sprint 42 Demo" release/sprint-42

---

Delete a CDE

删除CDE

bash
acli env:delete
Prompts you to select the environment to delete. Only CDEs can be deleted; production and standard environments cannot.

bash
acli env:delete
提示选择要删除的环境。仅CDE可被删除;生产环境和标准环境无法删除。

Deploy Code to an Environment

向环境部署代码

bash
acli api:environments:code-switch <environmentId> <branch>
Example:
bash
acli api:environments:code-switch 112927-9454a2b1-cce0-475e-ae5f-5374dbca9b0a master
Returns a notification UUID you can track with
acli app:task-wait <uuid>
.

bash
acli api:environments:code-switch <environmentId> <branch>
示例:
bash
acli api:environments:code-switch 112927-9454a2b1-cce0-475e-ae5f-5374dbca9b0a master
返回一个通知UUID,可通过
acli app:task-wait <uuid>
跟踪进度。

Mirror an Environment

镜像环境

Makes a destination environment identical to a source — copies code, database, files, and config.
bash
acli env:mirror <source-environment> <destination-environment>
Use environment aliases in the format
app-name.env
:
bash
acli env:mirror myapp.prod myapp.staging
Skip specific components:
bash
acli env:mirror myapp.prod myapp.staging \
  --no-code \      # -c: skip code
  --no-databases \ # -d: skip databases
  --no-files \     # -f: skip files
  --no-config      # -p: skip configuration
Warning: This overwrites the destination. All existing data in the destination environment is replaced.

使目标环境与源环境完全一致——复制代码、数据库、文件和配置。
bash
acli env:mirror <source-environment> <destination-environment>
使用格式为
app-name.env
的环境别名:
bash
acli env:mirror myapp.prod myapp.staging
跳过特定组件:
bash
acli env:mirror myapp.prod myapp.staging \
  --no-code \      # -c: 跳过代码
  --no-databases \ # -d: 跳过数据库
  --no-files \     # -f: 跳过文件
  --no-config      # -p: 跳过配置
警告: 此操作会覆盖目标环境。目标环境中的所有现有数据将被替换。

Copy Cron Tasks Between Environments

在环境之间复制定时任务(Cron)

Copy all cron tasks from one environment to another:
bash
acli env:cron-copy <source_env> <dest_env>
Example:
bash
acli env:cron-copy myapp.prod myapp.staging
Useful after mirroring an environment to ensure scheduled tasks match.

将所有定时任务从一个环境复制到另一个环境:
bash
acli env:cron-copy <source_env> <dest_env>
示例:
bash
acli env:cron-copy myapp.prod myapp.staging
在镜像环境后使用此命令非常有用,可确保定时任务保持一致。

Install an SSL Certificate

安装SSL证书

bash
acli env:certificate-create <certificate> <private-key>
Options:
bash
acli env:certificate-create \
  /path/to/cert.pem \
  /path/to/private-key.pem \
  --label="My SSL Cert" \
  --ca-certificates=/path/to/ca-bundle.pem \
  --legacy              # Use legacy SSL (non-SNI)
To install from an existing CSR:
bash
acli env:certificate-create cert.pem key.pem --csr-id=<csr-uuid>

bash
acli env:certificate-create <certificate> <private-key>
选项:
bash
acli env:certificate-create \
  /path/to/cert.pem \
  /path/to/private-key.pem \
  --label="My SSL Cert" \
  --ca-certificates=/path/to/ca-bundle.pem \
  --legacy              # 使用旧版SSL(非SNI)
从现有CSR安装:
bash
acli env:certificate-create cert.pem key.pem --csr-id=<csr-uuid>

Typical Workflows

典型工作流程

Set up a CDE for a feature branch

为功能分支设置CDE

bash
undefined
bash
undefined

Create the environment

创建环境

acli env:create "Feature: New Checkout" feature/new-checkout
acli env:create "Feature: New Checkout" feature/new-checkout

Mirror prod data to it

将生产环境数据镜像到该环境

acli env:mirror myapp.prod myapp.<new-cde-id>
undefined
acli env:mirror myapp.prod myapp.<new-cde-id>
undefined

Refresh staging from production

从生产环境刷新预发布环境

bash
acli env:mirror myapp.prod myapp.staging
bash
acli env:mirror myapp.prod myapp.staging

Promote staging to prod

将预发布环境代码推广到生产环境

bash
acli api:environments:code-switch <prod-env-id> main

bash
acli api:environments:code-switch <prod-env-id> main

Best Practices

最佳实践

  1. Mirror before testing — Always sync a CDE from prod or staging before QA.
  2. Clean up CDEs — Delete CDEs when done; they consume resources.
  3. Test deploys in staging first — Always deploy to staging before production.
  4. Copy crons after mirror — Run
    env:cron-copy
    after mirroring to keep scheduled tasks in sync.

  1. 测试前先镜像 —— 在QA测试前,务必将CDE与生产环境或预发布环境同步。
  2. 清理CDE —— 完成测试后删除CDE;它们会消耗资源。
  3. 先在预发布环境测试部署 —— 部署到生产环境前,务必先部署到预发布环境。
  4. 镜像后复制定时任务 —— 镜像完成后运行
    env:cron-copy
    ,确保定时任务保持同步。

Troubleshooting

故障排查

"Environment not found"

"环境未找到"

Check available environments:
bash
acli api:applications:environment-list
检查可用环境:
bash
acli api:applications:environment-list

Mirror fails midway

镜像中途失败

Check logs and retry. Use
--no-databases
or
--no-files
to skip the component that failed:
bash
acli env:mirror myapp.prod myapp.staging --no-files

查看日志并重试。使用
--no-databases
--no-files
跳过失败的组件:
bash
acli env:mirror myapp.prod myapp.staging --no-files

Related Topics

相关主题

  • Pull & Push — Sync local and Cloud environments
  • Application Management — Find application UUIDs
  • Remote Access — SSH and Drush on environments
  • 拉取与推送 —— 同步本地和Cloud环境
  • 应用管理 —— 查找应用UUID
  • 远程访问 —— 在环境上使用SSH和Drush