有一些很好的使用 MapReduce 和 DynamoDB 的指南。前几天我关注了这个,并将数据导出到 S3 相当轻松。我认为您最好的选择是创建一个执行备份任务的配置单元脚本,将其保存在 S3 存储桶中,然后使用适用于您的语言的 AWS API 实用地启动新的 EMR 作业流程,完成备份。您可以将其设置为 cron 作业。
将数据从 Dynamo 导出到 S3 的 Hive 脚本示例:
CREATE EXTERNAL TABLE my_table_dynamodb (
company_id string
,id string
,name string
,city string
,state string
,postal_code string)
STORED BY 'org.apache.hadoop.hive.dynamodb.DynamoDBStorageHandler'
TBLPROPERTIES ("dynamodb.table.name"="my_table","dynamodb.column.mapping" = "id:id,name:name,city:city,state:state,postal_code:postal_code");
CREATE EXTERNAL TABLE my_table_s3 (
,id string
,name string
,city string
,state string
,postal_code string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
LOCATION 's3://yourBucket/backup_path/dynamo/my_table';
INSERT OVERWRITE TABLE my_table_s3
SELECT * from my_table_dynamodb;
下面是一个 PHP 脚本示例,它将启动一个新的 EMR 作业流程:
$emr = new AmazonEMR();
$response = $emr->run_job_flow(
'My Test Job',
array(
"TerminationProtected" => "false",
"HadoopVersion" => "0.20.205",
"Ec2KeyName" => "my-key",
"KeepJobFlowAliveWhenNoSteps" => "false",
"InstanceGroups" => array(
array(
"Name" => "Master Instance Group",
"Market" => "ON_DEMAND",
"InstanceType" => "m1.small",
"InstanceCount" => 1,
"InstanceRole" => "MASTER",
),
array(
"Name" => "Core Instance Group",
"Market" => "ON_DEMAND",
"InstanceType" => "m1.small",
"InstanceCount" => 1,
"InstanceRole" => "CORE",
),
),
),
array(
"Name" => "My Test Job",
"AmiVersion" => "latest",
"Steps" => array(
array(
"HadoopJarStep" => array(
"Args" => array(
"s3://us-east-1.elasticmapreduce/libs/hive/hive-script",
"--base-path",
"s3://us-east-1.elasticmapreduce/libs/hive/",
"--install-hive",
"--hive-versions",
"0.7.1.3",
),
"Jar" => "s3://us-east-1.elasticmapreduce/libs/script-runner/script-runner.jar",
),
"Name" => "Setup Hive",
"ActionOnFailure" => "TERMINATE_JOB_FLOW",
),
array(
"HadoopJarStep" => array(
"Args" => array(
"s3://us-east-1.elasticmapreduce/libs/hive/hive-script",
"--base-path",
"s3://us-east-1.elasticmapreduce/libs/hive/",
"--hive-versions",
"0.7.1.3",
"--run-hive-script",
"--args",
"-f",
"s3n://myBucket/hive_scripts/hive_script.hql",
"-d",
"INPUT=Var_Value1",
"-d",
"LIB=Var_Value2",
"-d",
"OUTPUT=Var_Value3",
),
"Jar" => "s3://us-east-1.elasticmapreduce/libs/script-runner/script-runner.jar",
),
"Name" => "Run Hive Script",
"ActionOnFailure" => "CANCEL_AND_WAIT",
),
),
"LogUri" => "s3n://myBucket/logs",
)
);
}