

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

# 使用 的 DataSync 範例 AWS CLI
<a name="cli_datasync_code_examples"></a>

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 DataSync 來執行動作和實作常見案例。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

**Topics**
+ [動作](#actions)

## 動作
<a name="actions"></a>

### `update-location-azure-blob`
<a name="datasync_UpdateLocationAzureBlob_cli_topic"></a>

以下程式碼範例顯示如何使用 `update-location-azure-blob`。

**AWS CLI**  
**使用新的客服人員更新您的轉接位置**  
下列 `update-location-object-storage` 範例使用新的代理程式更新 Microsoft Azure Blob Storage 的 DataSync 位置。  

```
aws datasync update-location-azure-blob \
    --location-arn arn:aws:datasync:us-west-2:123456789012:location/loc-abcdef01234567890 \
    --agent-arns arn:aws:datasync:us-west-2:123456789012:agent/agent-1234567890abcdef0 \
    --sas-configuration '{ \
        "Token": "sas-token-for-azure-blob-storage-access" \
    }'
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《*AWS DataSync 使用者指南*》中的[取代您的代理程式](https://docs.aws.amazon.com/datasync/latest/userguide/replacing-agent.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdateLocationAzureBlob](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/datasync/update-location-azure-blob.html)。

### `update-location-hdfs`
<a name="datasync_UpdateLocationHdfs_cli_topic"></a>

以下程式碼範例顯示如何使用 `update-location-hdfs`。

**AWS CLI**  
**使用新的客服人員更新您的轉接位置**  
下列 `update-location-hdfs` 範例會使用新的代理程式更新您的 DataSync HDFS 位置。只有在 HDFS 叢集使用 Kerberos 進行身分驗證時，才需要 `--kerberos-keytab` 和 `--kerberos-krb5-conf` 選項。  

```
aws datasync update-location-hdfs \
    --location-arn arn:aws:datasync:us-west-2:123456789012:location/loc-abcdef01234567890 \
    --agent-arns arn:aws:datasync:us-west-2:123456789012:agent/agent-1234567890abcdef0 \
    --kerberos-keytab file://hdfs.keytab
    --kerberos-krb5-conf file://krb5.conf
```
`hdfs.keytab` 的內容：  

```
N/A. The content of this file is encrypted and not human readable.
```
`krb5.conf` 的內容：  

```
[libdefaults]
    default_realm = EXAMPLE.COM
    dns_lookup_realm = false
    dns_lookup_kdc = false
    rdns = true
    ticket_lifetime = 24h
    forwardable = true
    udp_preference_limit = 1000000
    default_tkt_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96 des3-cbc-sha1
    default_tgs_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96 des3-cbc-sha1
    permitted_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96 des3-cbc-sha1

[realms]
    EXAMPLE.COM = {
      kdc = kdc1.example.com
      admin_server = krbadmin.example.com
      default_domain = example.com
    }

[domain_realm]
    .example.com = EXAMPLE.COM
    example.com = EXAMPLE.COM

[logging]
    kdc = FILE:/var/log/krb5kdc.log
    admin_server = FILE:/var/log/kerberos/kadmin.log
    default = FILE:/var/log/krb5libs.log
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《*AWS DataSync 使用者指南*》中的[取代您的代理程式](https://docs.aws.amazon.com/datasync/latest/userguide/replacing-agent.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdateLocationHdfs](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/datasync/update-location-hdfs.html)。

### `update-location-nfs`
<a name="datasync_UpdateLocationNfs_cli_topic"></a>

以下程式碼範例顯示如何使用 `update-location-nfs`。

**AWS CLI**  
**使用新的客服人員更新您的轉接位置**  
下列 `update-location-nfs` 範例使用新的代理程式更新 DataSync NFS 位置。  

```
aws datasync update-location-nfs \
    --location-arn arn:aws:datasync:us-west-2:123456789012:location/loc-abcdef01234567890 \
    --on-prem-config AgentArns=arn:aws:datasync:us-west-2:123456789012:agent/agent-1234567890abcdef0
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《*AWS DataSync 使用者指南*》中的[取代您的代理程式](https://docs.aws.amazon.com/datasync/latest/userguide/replacing-agent.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdateLocationNfs](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/datasync/update-location-nfs.html)。

### `update-location-object-storage`
<a name="datasync_UpdateLocationObjectStorage_cli_topic"></a>

以下程式碼範例顯示如何使用 `update-location-object-storage`。

**AWS CLI**  
**使用新的客服人員更新您的轉接位置**  
下列 `update-location-object-storage` 範例使用新的代理程式更新您的 DataSync 物件存放位置。  

```
aws datasync update-location-object-storage \
    --location-arn arn:aws:datasync:us-west-2:123456789012:location/loc-abcdef01234567890 \
    --agent-arns arn:aws:datasync:us-west-2:123456789012:agent/agent-1234567890abcdef0 \
    --secret-key secret-key-for-object-storage
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《*AWS DataSync 使用者指南*》中的[取代您的代理程式](https://docs.aws.amazon.com/datasync/latest/userguide/replacing-agent.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdateLocationObjectStorage](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/datasync/update-location-object-storage.html)。

### `update-location-smb`
<a name="datasync_UpdateLocationSmb_cli_topic"></a>

以下程式碼範例顯示如何使用 `update-location-smb`。

**AWS CLI**  
**使用新的客服人員更新您的轉接位置**  
下列 `update-location-smb` 範例使用新的代理程式更新您的 DataSync SMB 位置。  

```
aws datasync update-location-smb \
    --location-arn arn:aws:datasync:us-west-2:123456789012:location/loc-abcdef01234567890 \
    --agent-arns arn:aws:datasync:us-west-2:123456789012:agent/agent-1234567890abcdef0 \
    --password smb-file-server-password
```
此命令不會產生輸出。  
如需詳細資訊，請參閱《*AWS DataSync 使用者指南*》中的[取代您的代理程式](https://docs.aws.amazon.com/datasync/latest/userguide/replacing-agent.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdateLocationSmb](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/datasync/update-location-smb.html)。