

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

以下代码示例演示如何通过将 AWS Command Line Interface与 DataSync 结合使用，来执行操作和实现常见场景。

*操作是大型程序的代码摘录*，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

**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)。