Azure: AzCopy для Linux – скопировать весь контейнер

Автор: | 24/11/2016
 

azure_logoТак как Azure CLI не предоставляет возможности скопировать сразу все файлы из контейнера в Storage Account на свою машину – ищем костыли и подпорки.

Одним из таких костылей является утилита AzCopy, которая доступна под Windows.

Для того, что иметь аналогичный функционал на Linux/macOS – была написана аналоигчная утулита – blobxfer.

Предсталвяет собой Python-скрипт.

Устанавливаем:

$ sudo pip install blobxfer

Проверяем:

$ blobxfer --help
usage: blobxfer [-h] [--autovhd] [--collate [COLLATE]] [--computeblockmd5]
                [--chunksizebytes CHUNKSIZEBYTES] [--delete]
                [--disable-urllib-warnings] [--download] [--encmode ENCMODE]
                [--endpoint ENDPOINT] [--fileshare] [--include INCLUDE]
...

Что бы выгрузить целый контейнер – выполняем:

$ blobxfer accountname containername STORAGE_BACKUP/ --remoteresource . --storageaccountkey=ELK***8Tw==
=====================================
 azure blobxfer parameters [v0.12.0]
=====================================
             platform: Linux-4.2.0-42-generic-x86_64-with-Ubuntu-14.04-trusty
   python interpreter: CPython 2.7.6
     package versions: az.common=1.1.4 az.sml=0.20.5 az.stor=0.33.0 crypt=1.6 req=2.11.1
      subscription id: None
      management cert: None
   transfer direction: local->Azure
       local resource: STORAGE_BACKUP/
      include pattern: None
      remote resource: .
...
script start time: 2016-11-24 11:15:52
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
WARNING: ignorning specified remoteresource . for directory upload
creating container, if needed: media
detected no transfer actions needed to be taken, exiting...

Устанавливаем зависимость (указана в документации):

$ sudo pip install ndg-httpsclient

Экспортим ключ в переменную, что бы не указывать его постоянно:

$ export BLOBXFER_STORAGEACCOUNTKEY=ELK***8Tw==

Загружаем один файл:

$ blobxfer accountname containername STORAGE_BACKUP/ --remoteresource 2016/11/kalimera_header-1.jpg --download
$ ls -l STORAGE_BACKUP/2016/11/kalimera_header-1.jpg
-rw-rw-r-- 1 setevoy setevoy 342391 лис 24 11:26 STORAGE_BACKUP/2016/11/kalimera_header-1.jpg

И весь контейнер:

$ azure blobxfer parameters [v0.12.0]
=====================================
             platform: Linux-4.2.0-42-generic-x86_64-with-Ubuntu-14.04-trusty
   python interpreter: CPython 2.7.6
     package versions: az.common=1.1.4 az.sml=0.20.5 az.stor=0.33.0 crypt=1.6 req=2.11.1
...
script start time: 2016-11-24 11:26:51
attempting to copy entire container media to STORAGE_BACKUP/
generating local directory structure and pre-allocating space                                                                                                                                                                                                                  
remote blob: 2016/11/161012_bcb_stand706-960x750.jpg length: 134628 bytes, md5: None
remote blob: 2016/11/003_wildherbhunt-768x1200.jpg length: 242746 bytes, md5: None
...
finalization complete.

script elapsed time: 139.632459164 sec
script end time: 2016-11-24 11:29:11

Проверяем:

$ ls -l STORAGE_BACKUP/
total 4108
drwxrwxr-x 3 setevoy setevoy    4096 лис 24 11:27 2012
drwxrwxr-x 3 setevoy setevoy    4096 лис 24 11:26 2014
drwxrwxr-x 5 setevoy setevoy    4096 лис 24 11:27 2016                                                                                                                                                                                                                         
-rw-rw-r-- 1 setevoy setevoy 4194304 лис 24 11:29 huber4M.png

Готово.