{Azure Storage}ブロック BLOB のオブジェクト レプリケーションを構成する



https://learn.microsoft.com/ja-jp/azure/storage/blobs/object-replication-configure?tabs=azure-cli
https://learn.microsoft.com/ja-jp/azure/storage/blobs/object-replication-overview


オブジェクトのレプリケーションでは、ソース アカウントと宛先アカウントの両方で BLOB のバージョン管理が有効になっている必要があります。
また、ソース アカウントで BLOB の変更フィードが有効になっている必要もあります。

 

-- 1. 前作業

az login --use-device-code
az account show

az version

az configure --list-defaults
az configure --defaults location=japaneast
az configure --list-defaults

az group create \
--name rg9999999 \
--location japaneast


az group list
az upgrade


-- 2. ストレージアカウントの作成

az storage account create \
--resource-group rg9999999 \
--name st12301 \
--access-tier Hot \
--kind StorageV2 \
--sku Standard_LRS

az storage account create \
--resource-group rg9999999 \
--name st12302 \
--access-tier Hot \
--kind StorageV2 \
--sku Standard_LRS


az storage account list \
--resource-group rg9999999


-- 3. ソースストレージアカウントでBLOBのバージョン管理と変更フィードを有効にする

az storage account blob-service-properties update \
--resource-group rg9999999 \
--account-name st12301 \
--enable-versioning true \
--enable-change-feed true

az storage account blob-service-properties show \
--resource-group rg9999999 \
--account-name st12301

-- 4. 宛先ストレージアカウントでBLOBのバージョン管理を有効にする

az storage account blob-service-properties update \
--resource-group rg9999999 \
--account-name st12302 \
--enable-versioning true


az storage account blob-service-properties show \
--resource-group rg9999999 \
--account-name st12302

 

-- 5. コンテナーの作成

key01=$(az storage account keys list \
--account-name st12301 \
--resource-group rg9999999 \
--output json \
--query [0].value | tr -d '"')

echo $key01

key02=$(az storage account keys list \
--account-name st12302 \
--resource-group rg9999999 \
--output json \
--query [0].value | tr -d '"')

echo $key02


az storage container create \
--name container01 \
--account-name st12301 \
--public-access off \
--account-key $key01

az storage container create \
--name container02 \
--account-name st12302 \
--public-access off \
--account-key $key02

az storage container list \
--account-name st12301 \
--account-key $key01

az storage container list \
--account-name st12302 \
--account-key $key02

 


-- 6. 宛先ストレージアカウントにレプリケーションポリシーを作成

az storage account or-policy create \
--account-name st12302 \
--resource-group rg9999999 \
--source-account st12301 \
--destination-account st12302 \
--source-container container01 \
--destination-container container02

az storage account or-policy list \
--account-name st12302 \
--resource-group rg9999999

az storage account or-policy show \
--account-name st12302 \
--resource-group rg9999999 \
--policy-id 11111111-1111-1111-1111-111111111111

 

-- 7. ソースストレージアカウントにレプリケーションポリシーを作成


az storage account or-policy show \
--resource-group rg9999999 \
--account-name st12302 \
--policy-id 11111111-1111-1111-1111-111111111111 > policy.json

cat policy.json


az storage account or-policy create \
--resource-group rg9999999 \
--account-name st12301 \
--policy @policy.json

 

az storage account or-policy list \
--account-name st12301 \
--resource-group rg9999999


az storage account or-policy show \
--account-name st12301 \
--resource-group rg9999999 \
--policy-id 11111111-1111-1111-1111-111111111111

 

-- 8. ソースストレージアカウントのコンテナーにオブジェクトをアップロード

echo test > test.txt

az storage blob upload \
--account-name st12301 \
--container-name container01 \
--name test.txt \
--file test.txt \
--account-key $key01

 

az storage blob list \
--account-name st12301 \
--container-name container01 \
--output table \
--account-key $key01


az storage blob list \
--account-name st12302 \
--container-name container02 \
--output table \
--account-key $key02

 

-- 9. BLOB のレプリケーションの状態を確認する

az storage blob show \
--account-name st12301 \
--container-name container01 \
--name test.txt \
--account-key $key01


az storage blob show \
--account-name st12301 \
--container-name container01 \
--name test.txt \
--account-key $key01 \
--query 'objectReplicationSourceProperties.rules.status' \
--output tsv

 

-- 10. クリーンアップ

az storage account delete \
--resource-group rg9999999 \
--name st12301 \
--yes

az storage account delete \
--resource-group rg9999999 \
--name st12302 \
--yes

az group list
az group delete \
--name rg9999999 \
--yes