ちょっと話題の記事

Amazon EBS Snapshotのリージョン間コピー機能リリース!

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

ついに来たリージョン間コピー!バッチリ災害対策!

Amazon EC2で使う仮想ハードディスクであるAmazon EBS(Elastic Block Store)のスナップショットが、リージョン間でコピーできるようになりました!今までリージョン間で何かしらデータをコピーするためには自前で用意するしか無かったのですが、遂に遂に登場です!これで災害対策を非常に簡単に実現できます。

画面からリージョン間コピー

早速AWS管理コンソールから使ってみましょう!EBSのメニューからSnapshot一覧を選択します。

region-copy-000

上部メニューに「コピー」というボタンが!!早速押します。

region-copy-001

ドロップダウンリストからコピーしたいリージョンを選択!

region-copy-002

コピー開始!今回はシンガポールリージョンに8GBのスナップショットをコピーしました。

region-copy-003

待つこと10分弱...完了!

region-copy-005

コンソールからリージョン間コピー

次はコンソールからリージョン間コピーをやってみたいと思います。最新のコンソールコマンドを使う必要がありますので、ダウンロードしましょう。バージョン1.6.6.0が確認できればOKです。

$ wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip
$ unzip ec2-api-tools.zip 
$ cd ec2-api-tools-1.6.6.0/
$ pwd
/home/ec2-user/ec2-api-tools-1.6.6.0/bin
$ EC2_HOME=/home/ec2-user/ec2-api-tools-1.6.6.0
$ ./ec2-version
1.6.6.0 2012-12-01

次にコマンド実行です。スナップショットのコピーコマンドを試してみます。

$ ./ec2-copy-snapshot --help
  SYNOPSIS
     ec2cpsnap ([ec2-copy-snapshot])
     ec2cpsnap [GENERAL OPTIONS] -r SOURCE_REGION -s SOURCE_SNAPSHOT_ID [-d DESCRIPTION]
  GENERAL NOTES
     Any command option/parameter may be passed a value of '-' to indicate
     that values for that option should be read from stdin.
  DESCRIPTION
     Copies a snapshot to this region from another region.

  GENERAL OPTIONS

     -O, --aws-access-key KEY
          AWS Access Key ID. Defaults to the value of the AWS_ACCESS_KEY
          environment variable (if set).

     -W, --aws-secret-key KEY
          AWS Secret Access Key. Defaults to the value of the AWS_SECRET_KEY
          environment variable (if set).

     -T, --security-token TOKEN
          AWS delegation token. Defaults to the value of the AWS_DELEGATION_TOKEN
          environment variable (if set).

     -K, --private-key KEY
          [DEPRECATED] Specify KEY as the private key to use. Defaults to the value of the
          EC2_PRIVATE_KEY environment variable (if set). Overrides the default.

     -C, --cert CERT
          [DEPRECATED] Specify CERT as the X509 certificate to use. Defaults to the value 
          of the EC2_CERT environment variable (if set). Overrides the default.

     -U, --url URL
          Specify URL as the web service URL to use. Defaults to the value of
          'https://ec2.amazonaws.com' (us-east-1) or to that of the
          EC2_URL environment variable (if set). Overrides the default.

     --region REGION
          Specify REGION as the web service region to use.
          This option will override the URL specified by the "-U URL" option
          and EC2_URL environment variable.
          This option defaults to the region specified by the EC2_URL environment variable
          or us-east-1 if this environment variable is not set.

     -v, --verbose
          Verbose output.

     -?, --help
          Display this help.

     -H, --headers
          Display column headers.

     --debug
          Display additional debugging information.

     --show-empty-fields
          Indicate empty fields.

     --hide-tags
          Do not display tags for tagged resources.

     --connection-timeout TIMEOUT
          Specify a connection timeout TIMEOUT (in seconds).

     --request-timeout TIMEOUT
          Specify a request timeout TIMEOUT (in seconds).

  SPECIFIC OPTIONS

     -d, --description
          An optional description of the snapshot.

     -r, --source-region SOURCE_REGION
          The region from which to copy the snapshot.

     -s, --source-snapshot-id SOURCE_SNAPSHOT_ID
          The snapshot to copy.

アクセスキーとシークレットキーとリージョンを指定してコピーします。

$ export AWS_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
$ export AWS_SECRET_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

まずはスナップショット一覧の表示

$ ./ec2-describe-snapshots --region ap-northeast-1
SNAPSHOT	snap-071d4XXX	vol-6ed84XXX	completed	2012-08-17T10:24:51+0000	100%	555623463934	5	7-Aug 2012
SNAPSHOT	snap-8cb1aXXX	vol-07574XXX	completed	2012-11-13T15:34:01+0000	100%	234293814336	8	e574d24_2012-11-13

次にスナップショットコピーです!記述のポイントは、東京からシンガポールにコピーするときは、リージョン指定をシンガポールにして、ソース指定を東京とします。

$ ./ec2-copy-snapshot --region ap-southeast-1 -r ap-northeast-1 -s snap-071d4XXX

スナップショット作成中か確認します。現在5%の進捗のようです。

$ ./ec2-describe-snapshots --region ap-southeast-1
SNAPSHOT	snap-54c36XXX	vol-8ff7eXXX	pending	2012-12-18T10:10:49+0000	5%	123293814234	5	[Copied snap-071d4229 from ap-northeast-1]

超簡単にリージョン間のスナップショットコピーができました!!!

まとめ

コマンド一発でリージョン間コピーが出来ますので、全自動で全世界にバックアップを取ることが出来ます!すごい!すごい!すごい!早速、運用中のプロジェクトに適応しますよ!!!

参考資料

Ability to copy an EBS snapshot