

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# **eb migrate**
<a name="eb3-migrate"></a>

## Description
<a name="eb3-migratedescription"></a>

將網際網路資訊服務 (IIS) 網站和應用程式從 Windows 伺服器遷移至 Elastic Beanstalk。命令會封裝您的應用程式、保留其組態，並將它們部署到新的 Elastic Beanstalk 環境。

如需遷移 IIS 網站和應用程式的詳細資訊，請參閱 [將 IIS 應用程式遷移至 Elastic Beanstalk](dotnet-migrating-applications.md)。

**注意**  
使用此命令之前，請確定您的系統符合下列要求：  
Internet Information Services (IIS) 7.0 版或更新版本
已安裝 Web Deploy 3.6 或更新版本
Windows 伺服器上的管理權限
AWS 已設定適當許可的登入資料
您的來源伺服器具有 AWS 服務的傳出網際網路存取權。

下列步驟摘要說明遷移程序：

1. 探索 IIS 網站及其組態。

1. 封裝應用程式內容和組態。

1. 建立 Elastic Beanstalk 環境和應用程式。

1. 使用保留的設定部署應用程式。

命令會在結構化目錄中建立遷移成品，如下列清單所示：

```
C:\migration_workspace\
└── .\migrations\latest\
    ├── upload_target.zip
    └── upload_target\
        ├── [SiteName].zip                      # One ZIP per default application of IIS site
        ├── [SiteName-ApplicationName].zip      # One ZIP per additional application
        ├── aws-windows-deployment-manifest.json
        └── ebmigrateScripts\
            ├── site_installer.ps1              # Site installation scripts
            ├── permission_handler.ps1          # Permission management
            └── other helper scripts
```

使用 **eb migrate cleanup** 管理這些成品。

## 語法
<a name="eb3-migratesyntax"></a>

**eb migrate *[options]***

**eb migrate explore *[options]***

**eb migrate cleanup *[options]***

在沒有引數的情況下執行 時， 會以非互動式模式**eb migrate**運作。若要在互動式模式中執行，請執行 **eb migrate --interactive**。

互動式模式命令會提示以下資訊：
+ 選取要遷移的 IIS 網站
+ 環境和應用程式名稱
+ 平台版本選擇
+ 執行個體類型和其他組態選項

## 子命令
<a name="eb3-migratesubcommands"></a>

### 探索
<a name="eb3-migrateexplore"></a>

**eb migrate explore** 子命令會檢查您的 IIS 伺服器並列出可用的網站。

使用此命令來顯示下列資訊：
+ 檢視伺服器上的所有 IIS 網站
+ 使用 `--verbose`，檢查詳細組態，包括：
  + 網站繫結和連接埠
  + 應用程式集區
  + 虛擬目錄及其實體路徑
  + 身分驗證設定

```
PS C:\migrations_workspace >  eb migrate explore
Default Web Site
Site2
site3
router
```

```
PS C:\migrations_workspace >  eb migrate explore --verbose
1: Default Web Site:
  - Bindings:
    - *:8083:
  - Application '/':
    - Application Pool: DefaultAppPool
    - Enabled Protocols: http
    - Virtual Directories:
      - /:
        - Physical Path: C:\inetpub\wwwroot
        - Logon Method: ClearText
  - Application '/dotnet-6-0':
    - Application Pool: DefaultAppPool
    - Enabled Protocols: http
    - Virtual Directories:
      - /:
        - Physical Path: C:\inetpub\AspNetCoreWebApps\CoreWebApp-6-0
        - Logon Method: ClearText
  - Application '/dotnet-8-0':
    - Application Pool: DefaultAppPool
    - Enabled Protocols: http
    - Virtual Directories:
      - /:
        - Physical Path: C:\inetpub\AspNetCoreWebApps\CoreWebApp-8-0
        - Logon Method: ClearText
2: Site2:
  - Bindings:
    - *:8081:
...
```

### 清除
<a name="eb3-migratecleanup"></a>

**eb migrate cleanup** 子命令會使用下列動作來管理遷移成品：
+ 在 中保留最新的成功遷移 `./migrations/latest`
+ 移除較舊的遷移目錄
+ 維護關鍵組態檔案

```
PS C:\migrations_workspace >   eb migrate cleanup
Are you sure you would like to cleanup older artifacts within `./migrations/`? (y/N):
```

使用 `--force` 在清除期間略過確認提示。

```
PS C:\migrations_workspace >   eb migrate cleanup --force
```

## 選項
<a name="eb3-migrateoptions"></a>

這些選項均非必要。如果您執行時**eb migrate**沒有任何選項，EB CLI 將以非互動式模式執行。使用 **eb migrate --interactive**，EB CLI 會提示您輸入或選取必要設定的值。


****  

|  名稱  |  描述  | 
| --- | --- | 
|  `-a` *application-name* 或 `--application-name` *application-name*  |  新 Elastic Beanstalk 應用程式的名稱。 類型：字串 預設：EBMigratedApp  | 
|  `--archive` *directory-or-zip*  |  目錄或 ZIP 檔案，其中包含 先前產生的原始碼**eb migrate --archive-only**。 使用此選項可部署先前建立的遷移套件。 範例：`--archive .\migrations\latest\upload_target` 或 `--archive .\migrations\latest\upload_target.zip`  | 
|  `-ao` 或 `--archive-only`  |  僅建立沒有部署的目的地封存目錄。 產生的目錄可以使用 **eb migrate**搭配 `archive`選項或 手動部署**eb deploy**。  | 
|  `-c` *subdomain-name* 或 `--cname` *subdomain-name*  |  要為遷移應用程式加上 CNAME DNS 項目前綴的子網域名稱。 類型：字串 預設：環境名稱  | 
|  `-cf` 或 `--copy-firewall-config`  |  將來源伺服器防火牆組態複製到具有作用中繫結的所有 HTTP 連接埠的目的地。 在 中建立對應的安全群組規則 AWS。  | 
|  `-es` *snapshot-id* 【*snapshot-id* ...】 或 `--ebs-snapshots` *snapshot-id* 【*snapshot-id* ...】  |  要與環境建立關聯的 Amazon EBS 快照 IDs 逗號分隔清單。 範例：`--ebs-snapshots snap-1234567890abcdef0, snap-0987654321fedcba1`  | 
|  `--encrypt-ebs-volumes`  |  強制加密所有新的 Amazon EBS 磁碟區。  這是全帳戶設定，會影響所有未來的 Amazon EBS 磁碟區建立。   | 
|  `-e` *environment-name* 或 `--environment-name` *environment-name*  |  新 Elastic Beanstalk 環境的名稱。 類型：字串 預設：EBMigratedEnv 限制條件：長度必須介於 4 到 40 個字元之間。只能包含字母、數字和連字號。名稱開頭或結尾不能為連字號 (-)。  | 
|  `--force`  |  在操作期間略過確認提示。 與**cleanup**子命令搭配使用時， 會移除遷移成品，無需確認。  | 
|  `-ip` *profile-name* 或 `--instance-profile` *profile-name*  |  要與環境 Amazon EC2 執行個體建立關聯的執行個體設定檔。 如果未指定， 會建立具有存取 Elastic Beanstalk 資源許可的預設執行個體描述檔。如需詳細資訊，請參閱[Elastic Beanstalk 執行個體描述檔](concepts-roles-instance.md)。  | 
|  `-i` *instance-type* 或 `--instance-type` *instance-type*  |  Elastic Beanstalk 環境的 Amazon EC2 執行個體類型。 類型：字串 預設：c5.2xlarge 如需可用的執行個體類型，請參閱[《Amazon EC2 使用者指南》中的 Amazon EC2 執行個體類型](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html)。 *Amazon EC2 *  | 
|  `-in` 或 `--interactive`  |  強制遷移程序的互動式模式。 即使預設值可用，也會提示組態值。  | 
|  `-k` *key-name* 或 `--keyname` *key-name*  |  Amazon EC2 金鑰對，以啟用環境執行個體的 RDP 存取。 可用於調查日誌中看不到的執行個體層級問題。 有效值：向 Amazon EC2 註冊的現有金鑰對名稱  | 
|  `-p` *platform-version* 或 `--platform` *platform-version*  |  環境的 Elastic Beanstalk 平台執行時間。如果未指定，則會自動從主機 Windows Server 版本偵測到 。 範例：`"64bit Windows Server 2016 v2.16.2 running IIS 10.0"` 如需可用平台版本的清單，請使用 [eb 平台清單](eb3-platform.md#eb3-platform-list)。  | 
|  `--remote`  |  指示 在遠端模式下執行遷移。此選項允許從堡壘主機執行，該主機會連線至目標伺服器，其中包含要遷移至 Elastic Beanstalk 的應用程式和組態。從堡壘伺服器執行、`eb migrate`探索組態、在堡壘主機上階段遷移邏輯，然後將您的應用程式部署到新的 Elastic Beanstalk 環境。 此選項不需要在您需要遷移的 Windows 伺服器上安裝 EB CLI 和 Python。您會改為在堡壘主機上安裝 Python 和 EB CLI，在堡壘主機上以 `--remote`選項執行**eb migrate**命令。使用 `--target-ip`選項指定具有要遷移之 IIS 組態的主機。 必須搭配 `--target-ip`、 `--username`和 使用`--password`。  | 
|  `--target-ip` *ip-address*  |  遠端 Windows 機器的公有 IP 地址，其中包含要遷移的 IIS 伺服器。 使用 時為必要`--remote`。只能在使用 時指定`--remote`。  | 
|  `--username` *使用者名稱*  |  存取遠端 Windows 機器的使用者設定檔使用者名稱，其中包含要遷移的 IIS 伺服器。 使用 時為必要`--remote`。只能在使用 時指定`--remote`。  | 
|  `--password` *密碼*  |  存取遠端 Windows 機器的使用者設定檔密碼，其中包含要遷移的 IIS 伺服器。 使用 時為必要`--remote`。只能在使用 時指定`--remote`。  | 
|  `-sr` *role-name* 或 `--service-role` *role-name*  |  Elastic Beanstalk 管理相關服務的 IAM AWS 服務角色。 如果未指定， 會建立具有必要許可的預設服務角色。如需詳細資訊，請參閱[Elastic Beanstalk 服務角色](concepts-roles-service.md)。  僅指定角色名稱，而非完整的 ARN。Elastic Beanstalk 會自動建立完整的 ARN。   | 
|  `-s` *site-names* 或 `--sites` *site-names*  |  要遷移的 IIS 站點逗號分隔清單。如果未指定， 會遷移伺服器上所有可用的網站。 範例：`--sites "Default Web Site,Intranet,API"`  | 
|  `--ssl-certificates` *certificate-arn*【，*certificate-arn* ...】  |  要與 Application Load Balancer 建立關聯的 ACM SSL 憑證 ARNs 逗號分隔清單。 使用 HTTPS 繫結遷移網站時為必要。 範例：`--ssl-certificates arn:aws:acm:region:account:certificate/certificate-id`  | 
|  `-t key1=value1[,key2=value2 ...]` 或 `-﻿-﻿tags key1=value1[,key2=value2 ...]`  |  以逗號分隔的`key=value`配對清單，以標記環境中的新資源：環境、Elastic Beanstalk 應用程式、應用程式版本。 如需詳細資訊，請參閱[標記環境](using-features.tagging.md)。  | 
|  `--verbose`  |  在遷移程序期間顯示詳細資訊。 與**explore**子命令搭配使用時， 會顯示完整的網站組態詳細資訊。  | 
|  `-vpc` *config-file-or-string* 或 `--vpc-config` *config-file-or-string*  |  環境的 VPC 組態，指定為 JSON 檔案路徑或 JSON 字串。 組態必須包含： <pre>{<br />    "id": "vpc-1234567890abcdef0",<br />    "publicip": "true|false",<br />    "elbscheme": "public|private",<br />    "ec2subnets": ["subnet-a1b2c3d4", "subnet-e5f6g7h8"],<br />    "securitygroups": "sg-123456,sg-789012",<br />    "elbsubnets": ["subnet-a1b2c3d4", "subnet-e5f6g7h8"]<br />}</pre> [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/elasticbeanstalk/latest/dg/eb3-migrate.html)  *當您指定 參數時，遷移會忽略來源環境中任何現有的 VPC 設定*`--vpc-config`。 **當您使用此參數時，遷移只會使用您傳入的組態檔案中指定的 VPC 設定。使用此參數會覆寫探索來源執行個體 VPC 組態或使用預設 VPC 的預設行為。   | 
|  [常用選項](eb3-cmd-options.md)  |  | 

## Output
<a name="eb3-migrateoutput"></a>

命令提供整個遷移程序的狀態更新：

1. VPC 組態偵測 （在 EC2 執行個體上執行時）

1. 每個網站的原始碼套件產生進度

1. 環境建立狀態

1. 部署進度

如果成功， 會顯示新環境的詳細資訊，包括：
+ 環境名稱和 ID
+ Application name (應用程式名稱)
+ 區域
+ 平台版本
+ 環境 CNAME

對於遷移期間的問題，請使用 [**eb events**](eb3-events.md)和 [**eb health**](eb3-health.md)命令來取得詳細資訊。

## 範例
<a name="eb3-migrateexamples"></a>

### 基本使用
<a name="eb3-migrateexamples-basic"></a>

在互動式模式中的基本遷移：

```
PS C:\migrations_workspace >  eb migrate
Identifying VPC configuration of this EC2 instance (i-0123456789abcdef0):
  id: vpc-1234567890abcdef0
  publicip: true
  elbscheme: public
  ec2subnets: subnet-123,subnet-456,subnet-789
  securitygroups: sg-123,sg-456
  elbsubnets: subnet-123,subnet-456,subnet-789

Using .\migrations\latest to contain artifacts for this migration run.
Generating source bundle for sites, applications, and virtual directories...
  Default Web Site/ -> .\migrations\latest\upload_target\DefaultWebSite.zip

Creating application version
Creating environment

Environment details for: EBMigratedEnv
  Application name: EBMigratedApp
  Region: us-west-2
  Deployed Version: app-230320_153045
  Environment ID: e-abcdef1234
  Platform: 64bit Windows Server 2019 v2.7.0 running IIS 10.0
  Tier: WebServer-Standard-1.0
  CNAME: ebmigratedenv.us-west-2.elasticbeanstalk.com
  Updated: 2023-03-20 15:30:45
```

使用自訂組態遷移特定網站：

```
PS C:\migrations_workspace >  eb migrate `
    --sites "Default Web Site,InternalAPI" `
    --application-name "CorporateApp" `
    --environment-name "Production" `
    --instance-type "c5.xlarge" `
    --tags "Environment=Production,Team=WebOps" `
    --copy-firewall-config
```

在沒有部署的情況下建立遷移封存：

```
PS C:\migrations_workspace >  eb migrate --archive-only
Using .\migrations\latest to contain artifacts for this migration run.
Generating source bundle for sites, applications, and virtual directories...
  Default Web Site/ -> .\migrations\latest\upload_target\DefaultWebSite.zip

Generated destination archive directory at .\migrations\latest\upload_target
You can execute `eb init` and `eb create` from this directory to deploy to EB.
```

### 進階組態範例
<a name="eb3-migrateexamples-advanced"></a>

使用 JSON 檔案遷移自訂 VPC 組態：

```
PS C:\migrations_workspace >  cat vpc-config.json
{
    "id": "vpc-1234567890abcdef0",
    "publicip": "false",
    "elbscheme": "internal",
    "ec2subnets": [
        "subnet-private1",
        "subnet-private2"
    ],
    "securitygroups": [
        "sg-app",
        "sg-database",
        "sg-monitoring"
    ],
    "elbsubnets": [
        "subnet-private1",
        "subnet-private2"
    ]
}

PS C:\migrations_workspace eb migrate `
    --sites "InternalAPI" `
    --vpc-config vpc-config.json `
    --instance-type "r5.xlarge" `
    --tags "Environment=Internal,Security=High"
```

使用 SSL 憑證和主機標頭遷移網站：

```
PS C:\migrations_workspace >  eb migrate `
    --sites "SecurePortal" `
    --ssl-certificates "arn:aws:acm:region:account:certificate/cert1,arn:aws:acm:region:account:certificate/cert2" `
    --verbose
INFO: Detected HTTPS bindings:
  - www.example.com:443
  - api.example.com:443

INFO: Configuring Application Load Balancer with SSL certificates
INFO: Creating host-based routing rules:
  - www.example.com -> target group 1
  - api.example.com -> target group 2
```

使用 EBS 快照組態進行遷移：fo

```
PS C:\migrations_workspace >  eb migrate `
    --sites "Default Web Site" `
    --ebs-snapshots "snap-1234567890abcdef0" "snap-0987654321fedcba1" `
    --encrypt-ebs-volumes
Using .\migrations\latest to contain artifacts for this migration run.
INFO: Enabling EBS encryption for all new volumes in us-west-2
INFO: Configuring environment with specified EBS snapshots
```

### 安全組態範例
<a name="eb3-migrateexamples-security"></a>

使用複雜的防火牆規則處理網站：

```
PS C:\migrations_workspace >  eb migrate `
    --sites "Default Web Site,ReportingService" `
    --copy-firewall-config `
    --verbose
INFO: Detected the following Windows Firewall rules:
  - Allow Web Traffic (TCP 80, 443)
  - Allow Reporting Traffic (TCP 8081)
INFO: Creating corresponding security group rules
```

使用自訂 IAM 角色進行遷移：

```
PS C:\migrations_workspace >  eb migrate `
    --sites "SecureApp" `
    --instance-profile "CustomInstanceProfile" `
    --service-role "CustomServiceRole"
```

### 遠端執行範例
<a name="eb3-migrateexamples-remote"></a>

從遠端 Windows 伺服器遷移 IIS 應用程式：

```
PS C:\migrations_workspace >  eb migrate `
    --remote `
    --target-ip "192.0.2.10" `
    --username "administrator" `
    --password "YourPassword123" `
    --application-name "RemoteApp" `
    --environment-name "RemoteEnv"
INFO: Establishing SSH connection to remote host 192.0.2.10...
INFO: Connection established
INFO: Discovering IIS sites on remote host...
INFO: Found 2 sites: Default Web Site, API
INFO: Extracting site configurations...
INFO: Generating source bundle for sites, applications, and virtual directories...
  Default Web Site/ -> .\migrations\latest\upload_target\DefaultWebSite.zip
  API/ -> .\migrations\latest\upload_target\API.zip

Creating application version
Creating environment

Environment details for: RemoteEnv
  Application name: RemoteAppstage mi
  Region: us-west-2
  Deployed Version: app-230320_153045
  Environment ID: e-abcdef1234
  Platform: 64bit Windows Server 2019 v2.7.0 running IIS 10.0
  Tier: WebServer-Standard-1.0
  CNAME: remoteenv.us-west-2.elasticbeanstalk.com
  Updated: 2023-03-20 15:30:45
```

具有特定網站選擇的遠端遷移：

```
PS C:\migrations_workspace >  eb migrate `
    --remote `
    --target-ip "192.0.2.10" `
    --username "administrator" `
    --password "YourPassword123" `
    --sites "API" `
    --instance-type "c5.large"
```