Azure Storage AzCopyでAmazon S3をデータソースとして指定できるので移行を試しました

2020.12.20

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

いわさです。

Microsoft Azure の AzCopy が、Amazon S3をデータソースとして指定することが出来るので、Azure Storageとの双方向のコピーを試しました。

先に結論だけ書くと、AzCopyを使っての Azure Storageから Amazon S3への移行はサポートされておらず出来ません。
最後に記載していますが、他の手法を取る必要があります。

AzCopy使用準備

AzCopyダウンロード

以下から環境にあわせたAzCopyをダウンロードします。
Download AzCopy

iwasa.takahito@iwasa ~ % azcopy --version
azcopy version 10.8.0

この記事では現在最新の、v10.8.0にて試します。

Azure認証情報の取得

Azureの認証はSASトークンを使います(AADも利用可)

まず、Azure Storageアカウントを作成します。
汎用v2で作成します。

AzureポータルからSAS生成します。
使用できるリソースの種類で全てを選択し、「SASと接続文字列を生成する」を押します。

SASトークンが生成されるので控えておきます。

使用時はリソースURLに含めてください。

https://mystorageaccount.blob.core.windows.net/mycontainer?<SAS-token>

AWS認証情報の取得

AWS側ではアクセスキーとシークレットを使います。
IAMでプログラムアクセス用ユーザーを作成し、AmazonS3FullAccessを付与しました。

こちらも控えておきます。

使用時は環境変数にセットしてください。

export AWS_ACCESS_KEY_ID=<access-key>
export AWS_SECRET_ACCESS_KEY=<secret-access-key>

※macの場合

Amazon S3 から Azure Storage へのコピー

S3上にバケット、オブジェクトを作成します。
今回は、暗号化なしパブリックバケットと暗号化あり(SSE-S3)プライベートバケットで試しました。

適当にフォルダとファイルをアップロードしました。

AzCopy実行

実行単位はいくつかあります。

この記事ではバケットのコピーを行ってみます。

構文は以下です。

azcopy copy 'https://s3.amazonaws.com/<bucket-name>' 'https://<storage-account-name>.blob.core.windows.net/<container-name>' --recursive=true

なお、コピー先AzureストレージアカウントにBlobコンテナーはまだ作っていない状態です。

iwasa.takahito@iwasa ~ % azcopy copy 'https://s3.amazonaws.com/azurecopybucket1' 'https://iwasa20201220storage.blob.core.windows.net/azurecopybucket1?sv=2019-12-12&ss=bfqt&srt=sco&sp=rwdlacupx&se=2020-12-20T15:42:42Z&st=2020-12-20T07:42:42Z&spr=https&sig=1dW39o9V2vLLw1%2FKGoQLC4i8oZ2IKhafLZxUEcXWlXU%D3' --recursive=true
INFO: Scanning...
INFO: Authenticating to source using S3AccessKey
INFO: Instead of transferring from the 's3.amazonaws.com' URL, in this version of AzCopy we recommend you use a region-specific endpoint to transfer from one specific region. E.g. s3.us-east-1.amazonaws.com or a virtual-hosted reference to a single bucket.
INFO: Any empty folders will not be processed, because source and/or destination doesn't have full folder support

Job 7eff8a80-3280-0741-7ca4-466531166dd6 has started
Log file is located at: /Users/iwasa.takahito/.azcopy/7eff8a80-3280-0741-7ca4-466531166dd6.log

0.0 %, 0 Done, 0 Failed, 2 Pending, 0 Skipped, 2 Total, 

Job 7eff8a80-3280-0741-7ca4-466531166dd6 summary
Elapsed Time (Minutes): 0.0334
Number of File Transfers: 2
Number of Folder Property Transfers: 0
Total Number of Transfers: 2
Number of Transfers Completed: 2
Number of Transfers Failed: 0
Number of Transfers Skipped: 0
TotalBytesTransferred: 711666
Final Job Status: Completed

iwasa.takahito@iwasa ~ %

バケットがコピーされていますね!
S3バケット = Blobコンテナーという関係性です。

2つ目のバケットもコピーしてみます。

コピーされました。

パブリックアクセスレベルはどちらもプライベートになっていました。
また、暗号化についてもAzureStorageアカウントで設定している暗号化設定およびスコープに依存しているようなので、コピー後に各種設定は行う必要がありそうです。

Azure Storage から Amazon S3 へのコピー

先程の手順と同じで、コマンドのSourceとDestinationだけ入れ替えて試してみます!

コピー用のコンテナーをAzureStorageに用意して実行します。

iwasa.takahito@iwasa ~ % azcopy copy 'https://iwasa20201220storage.blob.core.windows.net/awscopybucket1?sv=2019-12-12&ss=bfqt&srt=sco&sp=rwdlacupx&se=2020-12-20T15:42:42Z&st=2020-12-20T07:42:42Z&spr=https&sig=1dW39o9V2vLLw1%2FKGoQLC4i8oZ2IKhafLZxUEcXWlXU%D3' 'https://s3.amazonaws.com/awscopybucket1' --recursive=true
INFO: The parameters you supplied were Source: 'https://iwasa20201220storage.blob.core.windows.net/awscopybucket1?se=2020-12-20t15%3A42%3A42z&sig=-REDACTED-&sp=rwdlacupx&spr=https&srt=sco&ss=bfqt&st=2020-12-20t07%3A42%3A42z&sv=2019-12-12' of type Blob, and Destination: 'https://s3.amazonaws.com/awscopybucket1' of type S3
INFO: Based on the parameters supplied, a valid source-destination combination could not automatically be found. Please check the parameters you supplied.  If they are correct, please specify an exact source and destination type using the --from-to switch. Valid values are two-word phases of the form BlobLocal, LocalBlob etc.  Use the word 'Blob' for Blob Storage, 'Local' for the local file system, 'File' for Azure Files, and 'BlobFS' for ADLS Gen2. If you need a combination that is not supported yet, please log an issue on the AzCopy GitHub issues list.

failed to parse user input due to error: the inferred source/destination combination could not be identified, or is currently not supported
iwasa.takahito@iwasa ~ %

失敗しましたね。

AzCopyのIssue眺めてみたのですが、機能提案自体はされているようです。
Support for Azure to AWS copy #348

まとめ

S3 → Azure StorageであればAzCopyは選択肢になるかなと思います。

Azure Storage → S3 の場合、AzCopyは使えないので、他の方法を検討する必要があります。
AzCopyのIssueではrcloneを使う方法が案内されていましたが、AWSブログで azure-blob-to-s3 が紹介されていたので、今度試してみようと思います。

One way to migrate data from Azure Blob Storage to Amazon S3