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

上次更新时间:2020 年 3 月 27 日

我想要使用 AWS 命令行界面 (AWS CLI) 从 AWS Backup 恢复点还原 Amazon Elastic File System (Amazon EFS) 文件系统。该如何操作?

解决方法

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

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

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

2.    记下命令输出中的 ResourceArn

{
    "BackupJobs": [
        {
            "CompletionDate": 1584448353.589, 
            "BackupVaultArn": "arn:aws:backup:us-east-1:111222333444:backup-vault:Default", 
            "PercentDone": "0.0", 
            "RecoveryPointArn": "arn:aws:backup:us-east-1:111222333444:recovery-point:f29fe56c-8f44-4877-9ae6-9c6d5dce8935", 
            "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-c1234567", 
            "BackupJobId": "12ddf0b1-aed4-44ec-894f-0d74448949bd", 
            "StartBy": 1584451934.889, 
            "CreationDate": 1584448334.889, 
            "BackupVaultName": "Default"
        }, 
        {
            "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:09e9dafe-44a6-471a-b4e8-64c98219a480", 
            "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-gd1b761d", 
            "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-c1234567", "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-c1234567", "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.    记下命令输出中的 ResourceArn

{
    "BackupJobs": [
        {
            "CompletionDate": 1584448353.589, 
            "BackupVaultArn": "arn:aws:backup:us-east-1:111222333444:backup-vault:Default", 
            "PercentDone": "0.0", 
            "RecoveryPointArn": "arn:aws:backup:us-east-1:111222333444:recovery-point:f29fe56c-8f44-4877-9ae6-9c6d5dce8935", 
            "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-c1234567", 
            "BackupJobId": "12ddf0b1-aed4-44ec-894f-0d74448949bd", 
            "StartBy": 1584451934.889, 
            "CreationDate": 1584448334.889, 
            "BackupVaultName": "Default"
        }, 
        {
            "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:09e9dafe-44a6-471a-b4e8-64c98219a480", 
            "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-gd1b761d", 
            "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-c1234567", "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-17dda397", "newFileSystem": "true", "CreationToken": "d0c12345-678d-4071-bf30-8e7e54ab65df", "Encrypted": "false", "PerformanceMode":"generalPurpose"}'

这篇文章对您有帮助吗?

我们可以改进什么?


需要更多帮助?