Blob sync by AzCopy#

%%ai vioras
Azure CUIのazcopyコマンドについて

azcopyは、Azure Storageへの大量のデータ転送を高速に行うためのコマンドラインツールです。azcopyを使用すると、Azure Storageとの間でデータをコピーしたり、移動したりすることができます。このツールは、高いパフォーマンスと信頼性を提供し、大規模なデータ転送を効率的に行うことができます。

azcopyは以下の主な機能を提供します:

  • ローカルファイルシステムとAzure Blob Storage、Azure Files、Azure Table Storageの間のデータ転送

  • Azure Storage Service間でのデータのコピー

  • データ転送の並列処理と再試行機能

  • データ転送の進行状況の表示

基本的なコマンドの形式は以下のようになります:

azcopy [command] [arguments] [flags]

たとえば、ローカルファイルシステムからAzure Blob Storageにファイルを転送するためのコマンドは以下のようになります:

azcopy cp "/path/to/local/file" "https://[account].blob.core.windows.net/[container]/[path/to/blob]"

このコマンドは、ローカルファイルシステムから指定したAzure Blob Storageのコンテナにファイルをコピーします。

なお、azcopyを使用する前に、Azure CLIをインストールし、az loginコマンドを使用してAzureにログインする必要があります。また、データを転送するAzure Storageのアクセス許可も必要です。

%%ai vioras
azcopyは"az storage"に置き換わるのですか?

いえ、azcopyaz storageはそれぞれ異なる目的と機能を持つCLIツールで、一方が他方を完全に置き換えるものではありません。

  • azcopy: これは一種のデータ移動ツールで、大量のデータをAzure Storageとの間で高速かつ効率的に転送することが目的です。azcopyは特に大量のデータを扱う際に優れています。また、azcopyは単独のツールであり、Azure CLIの一部ではありません。

  • az storage: これはAzure CLIの一部であり、Azure Storageサービスと対話するための一連のコマンドを提供しています。これには、ストレージアカウントの作成、BLOBのアップロードやダウンロード、キューメッセージの操作などが含まれます。az storageコマンドはより一般的なストレージ操作を扱いますが、azcopyほどの高速データ転送機能は提供していません。

したがって、どちらのツールを使用するかは、特定のタスクや要件によります。大量のデータを高速に転送する必要がある場合はazcopy、より一般的なストレージ操作を行う場合はaz storageコマンドを使用します。

認証 (再認証する必要あり)#

Note

2023年9月現在、azcopy は標準とは異なるクレデンシャルキャッシュを参照しているため、再認証する必要があります。

!azcopy login status
INFO: You are currently not logged in. Please login using 'azcopy login'
!azcopy login
INFO: 'azcopy login' command will be deprecated starting release 10.22. Use auto-login instead. Visit https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-authorize-azure-active-directory#authorize-without-a-secret-store  to know more.
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code IBCUFZB44 to authenticate.

INFO: Logging in under the "Common" tenant. This will log the account in under its home tenant.
INFO: If you plan to use AzCopy with a B2B account (where the account's home tenant is separate from the tenant of the target storage account), please sign in under the target tenant with --tenant-id
INFO: Login succeeded.
!azcopy login status
INFO: You have successfully refreshed your token. Your login session is still active

Blobのリスト#

!azcopy list "https://ecsosaka416528d.blob.core.windows.net/textbook-2023/chapters/01"
INFO: Autologin not specified.
INFO: Authenticating to source using Azure AD
INFO: 01_intro.ipynb;  Content Length: 2.10 KiB
INFO: 02_openai.ipynb;  Content Length: 9.98 KiB
INFO: 03_chatgpt.ipynb;  Content Length: 1.50 KiB
INFO: 04_assignment.ipynb;  Content Length: 15.70 KiB
INFO: intro_add.md;  Content Length: 330.00 B
INFO: intro_add_4.md;  Content Length: 4.65 KiB
INFO: intro_add_5.md;  Content Length: 1.21 KiB
INFO: intro_add_6.md;  Content Length: 572.00 B
INFO: .ipynb_checkpoints/01_intro-checkpoint.ipynb;  Content Length: 1.74 KiB
INFO: .ipynb_checkpoints/02_openai-checkpoint.ipynb;  Content Length: 21.16 MiB
INFO: .ipynb_checkpoints/03_chatgpt-checkpoint.ipynb;  Content Length: 15.28 KiB
INFO: images/20230411.pptx;  Content Length: 16.14 MiB
INFO: images/fig-01.png;  Content Length: 991.62 KiB
INFO: images/fig-02.png;  Content Length: 597.31 KiB
INFO: images/fig-03.png;  Content Length: 53.36 KiB
INFO: images/fig-04.png;  Content Length: 75.16 KiB
INFO: images/fig-05.png;  Content Length: 67.42 KiB
INFO: images/fig-06.png;  Content Length: 168.48 KiB
INFO: images/fig-07.png;  Content Length: 77.82 KiB
INFO: images/fig-08.png;  Content Length: 60.65 KiB
INFO: images/fig-09.png;  Content Length: 65.40 KiB
INFO: images/fig-10.png;  Content Length: 73.01 KiB
INFO: images/fig-11.png;  Content Length: 83.22 KiB
INFO: images/fig-12.png;  Content Length: 222.04 KiB
INFO: images/fig-13.png;  Content Length: 148.36 KiB
INFO: images/fig-14.png;  Content Length: 158.27 KiB
INFO: images/fig-15.png;  Content Length: 149.57 KiB

ローカルのファイル・システムとBlobの同期#

!azcopy sync \
    "https://ecsosaka416528d.blob.core.windows.net/textbook-2023/chapters" \
    "/home/jovyan/chapters" --recursive=true
INFO: Autologin not specified.
INFO: Authenticating to source using Azure AD
INFO: Any empty folders will not be processed, because source and/or destination doesn't have full folder support

Job 510ab820-de2b-ac42-5e1a-37b6d02eb2e0 has started
Log file is located at: /home/jovyan/.azcopy/510ab820-de2b-ac42-5e1a-37b6d02eb2e0.log

100.0 %, 0 Done, 0 Failed, 0 Pending, 0 Total, 2-sec Throughput (Mb/s): 0

Job 510ab820-de2b-ac42-5e1a-37b6d02eb2e0 Summary
Files Scanned at Source: 190
Files Scanned at Destination: 190
Elapsed Time (Minutes): 0.0333
Number of Copy Transfers for Files: 0
Number of Copy Transfers for Folder Properties: 0 
Total Number Of Copy Transfers: 0
Number of Copy Transfers Completed: 0
Number of Copy Transfers Failed: 0
Number of Deletions at Destination: 0
Total Number of Bytes Transferred: 0
Total Number of Bytes Enumerated: 0
Final Job Status: Completed

Errata#