如何使用 AWS CLI 从 AWS Backup 恢复点还原 Amazon EFS 文件系统?

上次更新日期: 2022 年 1 月 5 日

我想要使用 AWS Command Line Interface (AWS CLI) 从 AWS Backup 恢复点还原 Amazon Elastic File System (Amazon EFS) 文件系统。

解决方法

从 AWS Backup 恢复点就地还原 EFS 文件系统

1.    运行 list-backup-Jobs 命令以获取要还原的 EFS 文件系统的 Amazon Resource Name (ARN)。您必须拥有该资源 ARN 才能从 AWS Backup 恢复点还原 EFS 文件系统。

$ aws backup list-backup-jobs --by-resource-type EFS --region us-east-1

注意:如果在运行 AWS CLI 命令时遇到错误,请确保您使用的是最新版本的 AWS CLI

2.    在命令输出中,记下 RecoverypointArn

{
    "BackupJobs": [
        {
            "CompletionDate": 1583305453.7, 
            "BackupVaultArn": "arn:aws:backup:us-east-1:111222333444:backup-vault:Default", 
            "PercentDone": "0.0", 
            "RecoveryPointArn": "arn:aws:backup:us-east-1:111222333444:recovery-point:123e4567-6cd9-464e-bb6b-13f70e79d347", 
            "ResourceType": "EFS", 
            "BackupSizeInBytes": 73, 
            "State": "COMPLETED", 
            "IamRoleArn": "arn:aws:iam::111222333444:role/service-role/AWSBackupDefaultServiceRole", 
            "ResourceArn": "arn:aws:elasticfilesystem:us-east-1:111222333444:file-system/fs-6a1dcba2", 
            "BackupJobId": "721ba96d-a656-4771-a1f4-78bcd0c930f8", 
            "StartBy": 1583309035.684, 
            "CreationDate": 1583305435.684, 
            "BackupVaultName": "Default"
        }
    ]
}

3.    要运行 start-restore-job 命令,您必须定义用于还原 EFS 实例的特定元数据。您可以在单独的 JSON 文件中定义该元数据,也可以将该元数据定义为命令中的参数。

要在单独的 JSON 文件中定义该元数据,请创建一个与以下类似的 JSON 文件:

{"file-system-id": "fs-6a1dcba2", "newFileSystem": "false", "Encrypted": "false", "PerformanceMode":"generalPurpose"}

然后运行 start-restore-job 命令:

aws backup start-restore-job --region us-east-1 --recovery-point-arn "arn:aws:backup:us-east-1:111222333444:recovery-point:123e4567-6cd9-464e-bb6b-13f70e79d347" --iam-role-arn "arn:aws:iam::111222333444:role/service-role/AWSBackupDefaultServiceRole"  --metadata file://path_to_json_file

要将该元数据定义为 start-restore-job 命令中的参数,请用以下格式运行命令:

aws backup start-restore-job --region us-east-1 --recovery-point-arn "arn:aws:backup:us-east-1:111222333444:recovery-point:123e4567-6cd9-464e-bb6b-13f70e79d347" --iam-role-arn "arn:aws:iam::111222333444:role/service-role/AWSBackupDefaultServiceRole" --metadata '{"file-system-id": "fs-6a1dcba2", "newFileSystem": "false", "Encrypted": "false", "PerformanceMode":"generalPurpose"}'

从 AWS Backup 恢复点还原到新的 EFS 文件系统

1.    运行 list-backup-Jobs 命令以获取要还原的 EFS 文件系统的 ARN。您必须拥有该资源 ARN 才能从 AWS Backup 恢复点还原 EFS 文件系统。

$ aws backup list-backup-jobs --by-resource-type EFS --region us-east-1

2.    在命令输出中,记下 RecoverypointArn

{
    "BackupJobs": [
        {
            "CompletionDate": 1583305453.7, 
            "BackupVaultArn": "arn:aws:backup:us-east-1:111222333444:backup-vault:Default", 
            "PercentDone": "0.0", 
            "RecoveryPointArn": "arn:aws:backup:us-east-1:111222333444:recovery-point:123e4567-6cd9-464e-bb6b-13f70e79d347", 
            "ResourceType": "EFS", 
            "BackupSizeInBytes": 73, 
            "State": "COMPLETED", 
            "IamRoleArn": "arn:aws:iam::111222333444:role/service-role/AWSBackupDefaultServiceRole", 
            "ResourceArn": "arn:aws:elasticfilesystem:us-east-1:111222333444:file-system/fs-6a1dcba2", 
            "BackupJobId": "721ba96d-a656-4771-a1f4-78bcd0c930f8", 
            "StartBy": 1583309035.684, 
            "CreationDate": 1583305435.684, 
            "BackupVaultName": "Default"
        }
    ]
}

3.    要还原到新的 EFS 文件系统,您需要生成一个强制执行请求唯一性(幂等性)的 CreationToken 值。CreationToken 可以是您选择的任何值。在 Linux 操作系统上,您可以运行 uuid 命令来生成唯一标识符:

uuid -r

输出是一个全局唯一标识符 (UUID),与以下类似:

d0c12345-678d-4071-bf30-8e7e54ab65df

4.    要运行 start-restore-job 命令,您必须定义用于还原 EFS 实例的特定元数据。您可以在单独的 JSON 文件中定义该元数据,也可以将该元数据定义为命令中的参数。

要在单独的 JSON 文件中定义该元数据,请创建一个与以下类似的 JSON 文件:

注意:对于 CreationToken,请使用您在第 3 步中生成的 CreationToken 值。

{"file-system-id": "fs-6a1dcba2", "Encrypted": "false", "PerformanceMode": "generalPurpose", "CreationToken": "d0c12345-678d-4071-bf30-8e7e54ab65df", "newFileSystem": "true"}

然后运行 start-restore-job 命令:

注意:对于 --metadata,请输入您在上一步中创建的 JSON 文件。

aws backup start-restore-job --region us-east-1 --recovery-point-arn "arn:aws:backup:us-east-1:111222333444:recovery-point:123e4567-6cd9-464e-bb6b-13f70e79d347" --iam-role-arn "arn:aws:iam::111222333444:role/service-role/AWSBackupDefaultServiceRole"  --metadata file://path_to_json_file

要将该元数据定义为 start-restore-job 命令中的参数,请用以下格式运行命令:

注意:对于 CreationToken,请使用您在第 3 步中生成的 CreationToken 值。

aws backup start-restore-job --region us-east-1 --recovery-point-arn "arn:aws:backup:us-east-1:111222333444:recovery-point:123e4567-6cd9-464e-bb6b-13f70e79d347" --iam-role-arn "arn:aws:iam::111222333444:role/service-role/AWSBackupDefaultServiceRole" --metadata '{"file-system-id": "fs-6a1dcba2", "newFileSystem": "true", "CreationToken": "d0c12345-678d-4071-bf30-8e7e54ab65df", "Encrypted": "false", "PerformanceMode":"generalPurpose"}'

从 AWS Backup 恢复点执行项目级别 EFS 文件系统还原

1.    运行 list-backup-Jobs 命令以获取要还原的 EFS 文件系统的 Amazon Resource Name (ARN)。您必须拥有该资源 ARN 才能从 AWS Backup 恢复点还原 EFS 文件系统。
$ aws backup list-backup-jobs --by-resource-type EFS --region us-east-1

注意:如果在运行 AWS CLI 命令时遇到错误,请确保您使用的是最新版本的 AWS CLI

2.    在命令输出中,记下 RecoverypointArn

{
    "BackupJobs": [
        {
            "AccountId": "686948106210",
            "BackupJobId": "261f13d0-5ede-458e-a00e-d83ed5de0afe",
            "BackupVaultName": "Default",
            "BackupVaultArn": "arn:aws:backup:us-east-1:111222333444:backup-vault:Default",
            "RecoveryPointArn": "arn:aws:backup:us-east-1:111222333444:recovery-point:123e4567-6cd9-464e-bb6b-13f70e79d347",
            "ResourceArn": "arn:aws:elasticfilesystem:us-east-1:111222333444:file-system/fs-6a1dcba2",
            "CreationDate": "2021-08-23T07:52:56.652000+00:00",
            "CompletionDate": "2021-08-23T07:53:09.547000+00:00",
            "State": "COMPLETED",
            "PercentDone": "100.0",
            "BackupSizeInBytes": 75,
            "IamRoleArn": "arn:aws:iam::111222333444:role/service-role/AWSBackupDefaultServiceRole",
            "StartBy": "2021-08-23T08:52:56.652000+00:00",
            "ResourceType": "EFS"
        }

3.    要运行 start-restore-job 命令,您必须定义用于还原 EFS 实例的特定元数据。您可以在单独的 JSON 文件中定义该元数据,也可以将该元数据定义为命令中的参数。

要在单独的 JSON 文件中定义该元数据,请创建一个与以下类似的 JSON 文件:

{"file-system-id": "fs-6a1dcba2", "newFileSystem": "false", "Encrypted": "false", "PerformanceMode":"generalPurpose", "itemsToRestore":"[\"/my.test\"]"}

然后运行 start-restore-job 命令:

aws backup start-restore-job --region us-east-1 --recovery-point-arn "arn:aws:backup:us-east-1:111222333444:recovery-point:123e4567-6cd9-464e-bb6b-13f70e79d347" --iam-role-arn "arn:aws:iam::111222333444:role/service-role/AWSBackupDefaultServiceRole"  --metadata file://path_to_json_file

要将该元数据定义为 start-restore-job 命令中的参数,请用以下格式运行命令:

aws backup start-restore-job --region us-east-1 --recovery-point-arn "arn:aws:backup:us-east-1:111222333444:recovery-point:123e4567-6cd9-464e-bb6b-13f70e79d347" --iam-role-arn "arn:aws:iam::111222333444:role/service-role/AWSBackupDefaultServiceRole" --metadata '{"file-system-id": "fs-6a1dcba2", "newFileSystem": "false", "Encrypted": "false", "PerformanceMode":"generalPurpose", "itemsToRestore":"[\"/my.test\"]"}'

这篇文章对您有帮助吗?


您是否需要账单或技术支持?