本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用HBase快照
HBase 使用內建快照command-runner.jar
搭配 AWS CLI 或 的步驟執行這些命令 AWS SDK for Java。如需其他HBase備份類型的詳細資訊,請參閱 HBase 文件中的HBase備份
使用表格建立快照
hbase snapshot create -n
snapshotName
-ttableName
從 使用 command-runner.jar AWS CLI:
aws emr add-steps --cluster-id j-2AXXXXXXGAPLF \ --steps Name="HBase Shell Step",Jar="command-runner.jar",\ Args=[ "hbase", "snapshot", "create","-n","
snapshotName
","-t","tableName
"]
AWS SDK for Java
HadoopJarStepConfig hbaseSnapshotConf = new HadoopJarStepConfig() .withJar("command-runner.jar") .withArgs("hbase","snapshot","create","-n","snapshotName","-t","tableName");
注意
如果您的快照名稱不是唯一的,該建立操作會失敗並傳回程式碼 -1
或 255
,但您可能不會看到何處出錯的錯誤訊息。若要使用相同的快照名稱,請刪除它後再重新建立。
刪除快照
hbase shell >> delete_snapshot '
snapshotName
'
查看快照資訊
hbase snapshot info -snapshot
snapshotName
將快照匯出至 Amazon S3
重要
如果您在匯出快照時未指定-mappers
值, HBase會使用任意計算來判斷映射器的數量。根據您的表格大小,此值可以非常大,也會在匯出期間對執行中的任務有負面影響。因此,我們建議您指定 -mappers
、-bandwidth
參數 (指定每秒多少 MB 的頻寬耗用量),或兩者一起使用,以限制匯出操作的叢集資源。或者,您可以在低使用量期間執行匯出快照操作。
hbase snapshot export -snapshot
snapshotName
\ -copy-to s3://amzn-s3-demo-bucket
/folder
-mappers 2
command-runner.jar
從 使用 AWS CLI:
aws emr add-steps --cluster-id j-2AXXXXXXGAPLF \ --steps Name="HBase Shell Step",Jar="command-runner.jar",\ Args=[ "hbase", "snapshot", "export","-snapshot","
snapshotName
","-copy-to","s3://amzn-s3-demo-bucket
/folder
","-mappers","2","-bandwidth","50"]
AWS SDK for Java:
HadoopJarStepConfig hbaseImportSnapshotConf = new HadoopJarStepConfig() .withJar("command-runner.jar") .withArgs("hbase","snapshot","export", "-snapshot","snapshotName","-copy-to", "s3://bucketName/folder", "-mappers","2","-bandwidth","50");
從 Amazon S3 匯入快照
雖然這是匯入,但這裡使用HBase的選項仍然是 export
。
sudo -u hbase hbase snapshot export \ -D hbase.rootdir=s3://
amzn-s3-demo-bucket
/folder
\ -snapshotsnapshotName
\ -copy-to hdfs://masterPublicDNSName
:8020/user/hbase \ -mappers 2
command-runner.jar
從 使用 AWS CLI:
aws emr add-steps --cluster-id j-2AXXXXXXGAPLF \ --steps Name="HBase Shell Step",Jar="command-runner.jar", \ Args=["sudo","-u","hbase","hbase snapshot export","-snapshot","
snapshotName
", \ "-D","hbase.rootdir=s3://amzn-s3-demo-bucket
/folder
", \ "-copy-to","hdfs://masterPublicDNSName
:8020/user/hbase","-mappers","2","-chmod","700"]
AWS SDK for Java:
HadoopJarStepConfig hbaseImportSnapshotConf = new HadoopJarStepConfig() .withJar("command-runner.jar") .withArgs("sudo","-u","hbase","hbase","snapshot","export", "-D","hbase.rootdir=s3://path/to/snapshot", "-snapshot","snapshotName","-copy-to", "hdfs://masterPublicDNSName:8020/user/hbase", "-mappers","2","-chuser","hbase");
從 HBase shell 內的快照還原資料表
hbase shell >> disable
tableName
>> restore_snapshotsnapshotName
>> enabletableName
HBase 目前不支援HBase在 Shell 中找到的所有快照命令。例如,沒有HBase命令列選項可還原快照,因此您必須在 shell 中還原快照。這表示 command-runner.jar
必須執行 Bash 命令。
注意
由於這裡使用的命令是 echo
,即使 Amazon 執行的命令EMR傳回0
結束碼,您的 shell 命令仍可能會失敗。若您選擇執行一個 shell 命令做為步驟,請檢查該步驟日誌。
echo 'disable
tableName
; \ restore_snapshotsnapshotName
; \ enabletableName
' | hbase shell
以下是使用 AWS CLI的步驟。首先,建立以下 snapshot.json
檔案:
[ { "Name": "restore", "Args": ["bash", "-c", "echo $'disable \"
tableName
\"; restore_snapshot \"snapshotName
\"; enable \"tableName
\"' | hbase shell"], "Jar": "command-runner.jar", "ActionOnFailure": "CONTINUE", "Type": "CUSTOM_JAR" } ]
aws emr add-steps --cluster-id j-2AXXXXXXGAPLF \ --steps file://./snapshot.json
AWS SDK for Java:
HadoopJarStepConfig hbaseRestoreSnapshotConf = new HadoopJarStepConfig() .withJar("command-runner.jar") .withArgs("bash","-c","echo $'disable \"tableName\"; restore_snapshot \"snapshotName\"; enable \"snapshotName\"' | hbase shell");