facebook twitter hatena line email

「Azure/CLI」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(コンテナupload(dir)新)
(コンテナにupload時にファイル同期)
(同じ利用者による、間の5版が非表示)
行95: 行95:
  
 
az storage fs directoryが良いらしい
 
az storage fs directoryが良いらしい
 +
 +
===unrecognized argumentsエラーが出る===
 +
大きめサイズのjsonで起こった。謎だったが、blob syncを使ってuploadできたの良しとした。
  
 
==コンテナupload(dir)新==
 
==コンテナupload(dir)新==
行107: 行110:
  
 
公式:https://docs.microsoft.com/ja-jp/cli/azure/storage/fs/directory?view=azure-cli-latest#az_storage_fs_directory_upload
 
公式:https://docs.microsoft.com/ja-jp/cli/azure/storage/fs/directory?view=azure-cli-latest#az_storage_fs_directory_upload
 +
 +
===Failed to perform copy operation.エラーが出る===
 +
これは常に出てた・・・。ログを見ると以下が出てた。
 +
RESPONSE Status: 409 This endpoint does not support BlobStorageEvents or SoftDelete. Please disable these account features if you would like to use this endpoint.
 +
BlobStorageEventsまたはSoftDeleteをサポートしていません。ということ。
  
 
==コンテナにupload時にファイル同期==
 
==コンテナにupload時にファイル同期==
行116: 行124:
 
     -d dir1
 
     -d dir1
 
</pre>
 
</pre>
 +
 +
* --source -s:同期元のソースファイルのパス。
 +
* --destination -d:Blob 名の前に付加される宛先パス。
  
 
==コンテナ内リスト取得==
 
==コンテナ内リスト取得==

2021年8月20日 (金) 22:03時点における版

インストール

macの場合

brew update && brew install azure-cli

公式:https://docs.microsoft.com/ja-jp/cli/azure/install-azure-cli

login

az login

ブラウザに飛び、ログインが成功すると、以下メッセージが帰ってくる

The default web browser has been opened at https://login.microsoftonline.com/common/oauth2/authorize. Please continue the login in the web browser. If no web browser is available or if the web browser fails to open, use device code flow with `az login --use-device-code`.
You have logged in. Now let us find all the subscriptions to which you have access...
The following tenants don't contain accessible subscriptions. Use 'az login --allow-no-subscriptions' to have tenant level access.
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx '既定のディレクトリ'
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx 'hogeuser'
[
  {
    "cloudName": "AzureCloud",
    "homeTenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx",
    "isDefault": true,
    "managedByTenants": [],
    "name": "dv_xxx_cloudconfig-virtual-event-service_azureplan",
    "state": "Enabled",
    "tenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "user": {
      "name": "hogehoge@example.com",
      "type": "user"
    }
  }
]

コマンドにloginコマンドをつける

  • --auth-mode login
  • --connection-string, --account-key
  • --sas-token

auth-mode login

途中でブラウザのログイン画面に移動

sas-token

azure管理画面のコンテナの共有アクセストークンでアクセス許可の読み取り、追加、作成、書き込み、削除、リストなどをつけて、BLOB SASトークンをコピー

sp=racwdl&st=2021-03-20T11:50:30Z&se=2021-03-20T19:50:30Z&spr=https&sv=2020-08-04&sr=c&sig=xxxxxxZOIc8I4VptWt63fxrfV3Fh8G631XKtFcOxxxx%3D

コマンドにするときは以下のように、&を\&にエスケープしておく。

--sas-token sp=racwdl\&st=2021-03-20T11:50:30Z\&se=2021-03-20T19:50:30Z\&spr=https\&sv=2020-08-04\&sr=c\&sig=xxxxxxZOIc8I4VptWt63fxrfV3Fh8G631XKtFcOxxxx%3D

権限エラーが出るとき

RESPONSE Status: 403 This request is not authorized to perform this operation using this permission.

azure管理画面のコンテナの共有アクセストークンで、適切な権限が、ついてないので確認する

コンテナupload

az storage blob upload \
    --account-name <storage-account> \
    --container-name <container> \
    --name dir1/text.txt \
    --file /Users/user1/Desktop/test.txt \
    --auth-mode login
  • storage-accountは、左上のストレージアカウント
  • container-nameはコンテナーを選択した際に表示されるコンテナリスト内の名前
  • nameはazure内のpath
  • fileはローカル内のpath


公式:https://docs.microsoft.com/ja-jp/azure/storage/blobs/storage-quickstart-blobs-cli

コンテナupload(dir)旧

az storage blob directory upload \
    --account-name <storage-account> \
    -c <container> \ 
    -s "path/to/directory/*" \
    -d dir1 --recursive

引数指定で、DIRの上げ方は色々ある

-s "path/to/file" -d directory
-s "path/to/directory" -d directory --recursive
-s "path/to/*" -d directory --recursive

--container/-cのエラーが出たら

the following arguments are required: --container/-c

コンテナ引数は--container-nameではなく --containerか、-cにするとよい。

storage-previewのメッセージが出てきたら

The command requires the extension storage-preview. Do you want to install it now? The command will continue to run after the extension is installed. (Y/n): 

yを押してインストール

storage blob directoryは非推奨

This command is implicitly deprecated because command group 'storage blob directory' is deprecated and will be removed in a future release. Use 'az storage fs directory' instead

az storage fs directoryが良いらしい

unrecognized argumentsエラーが出る

大きめサイズのjsonで起こった。謎だったが、blob syncを使ってuploadできたの良しとした。

コンテナupload(dir)新

az storage fs directory upload \
    --account-name <storage-account> \
    --file-system <container> \ 
    -s "path/to/directory/*" \
    -d dir1 --recursive
  • -fは--file-systemでコンテナ名を入れる

公式:https://docs.microsoft.com/ja-jp/cli/azure/storage/fs/directory?view=azure-cli-latest#az_storage_fs_directory_upload

Failed to perform copy operation.エラーが出る

これは常に出てた・・・。ログを見ると以下が出てた。

RESPONSE Status: 409 This endpoint does not support BlobStorageEvents or SoftDelete. Please disable these account features if you would like to use this endpoint.

BlobStorageEventsまたはSoftDeleteをサポートしていません。ということ。

コンテナにupload時にファイル同期

az storage blob sync \
    --account-name <storage-account> \
    --container <container> \ 
    -s "path/to/directory" \
    -d dir1
  • --source -s:同期元のソースファイルのパス。
  • --destination -d:Blob 名の前に付加される宛先パス。

コンテナ内リスト取得

$ az storage blob list \
   --account-name <storage-account> \
   --container-name hoge-workspace \
   --auth-mode login \
   | grep name
   "name": "dir1/file1.txt,
   "name": "dir1/file2.txt",
  • storage-accountは、左上のストレージアカウント

参考:https://www.se-from30.com/azure/azurecli-az-storage-blob-01/