Skip to content

Instantly share code, notes, and snippets.

@shawnweisfeld
Last active March 20, 2021 14:35
Show Gist options
  • Save shawnweisfeld/aa4db3d56d3a9b28137e9aba8b02888f to your computer and use it in GitHub Desktop.
Save shawnweisfeld/aa4db3d56d3a9b28137e9aba8b02888f to your computer and use it in GitHub Desktop.
# Object Replication Demo
# 0. Setup some variables and create the resource group
# - in this sample we are using the same container name for source and destination this is not required
# - in this sample we are using the same region for source and destination this is not required
# - in this sample we are using the same durability (i.e. LRS) for source and destination this is not required
RG="sweisfelortest"
LOCATION="westus"
SRCACCT="sweisfelsrc$RANDOM"
DESTACCT="sweisfeldest$RANDOM"
CONTAINER="test"
az group create --name $RG --location $LOCATION
# 1. Create the source & destination storage accounts
# - Turn on Change Feed and Versioning features
# - You might need to wait a bit for the features to enable before moving to the next step
az deployment group create \
--name TestDeployment \
--resource-group $RG \
--template-file step01.json \
--parameters "storageNameSrc=$SRCACCT" \
"storageNameDest=$DESTACCT" \
"containerName=$CONTAINER"
# 2. Create the destination OR endpoint
az deployment group create \
--name TestDeployment \
--resource-group $RG \
--template-file step02.json \
--parameters "storageNameSrc=$SRCACCT" \
"storageNameDest=$DESTACCT" \
"containerName=$CONTAINER"
# 3. Create the source OR endpoint
# - NOTE: here I am just pulling the first policy and rule, since I only have 1
# - if you have more than 1 you will need to change the --query
POLICY=$(az storage account or-policy list --account-name $DESTACCT --query '[0].policyId' --output tsv)
RULE=$(az storage account or-policy list --account-name $DESTACCT --query '[0].rules[0].ruleId' --output tsv)
az deployment group create \
--name TestDeployment \
--resource-group $RG \
--template-file step03.json \
--parameters "storageNameSrc=$SRCACCT" \
"storageNameDest=$DESTACCT" \
"containerName=$CONTAINER" \
"policyId=$POLICY" \
"ruleId=$RULE"
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageNameSrc": {
"type": "string",
"metadata": {
"description": "The source storage account name."
}
},
"storageNameDest": {
"type": "string",
"metadata": {
"description": "The source storage account name."
}
},
"containerName": {
"type": "string",
"metadata": {
"description": "The container name to use in the source/dest accounts."
}
}
},
"variables": {
"location": "[resourceGroup().location]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-06-01",
"name": "[parameters('storageNameSrc')]",
"location": "[variables('location')]",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"properties": { },
"resources": [
{
"type": "blobServices/containers",
"apiVersion": "2019-06-01",
"name": "[concat('default/', parameters('containerName'))]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageNameSrc'))]"
]
},
{
"type": "Microsoft.Storage/storageAccounts/blobServices",
"apiVersion": "2020-08-01-preview",
"name": "[concat(parameters('storageNameSrc'), '/default')]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageNameSrc'))]"
],
"properties": {
"changeFeed": {
"enabled": "true"
},
"isVersioningEnabled": "true"
}
}
]
},
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-06-01",
"name": "[parameters('storageNameDest')]",
"location": "[variables('location')]",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"properties": { },
"resources": [
{
"type": "blobServices/containers",
"apiVersion": "2019-06-01",
"name": "[concat('default/', parameters('containerName'))]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageNameDest'))]",
]
},
{
"type": "Microsoft.Storage/storageAccounts/blobServices",
"apiVersion": "2020-08-01-preview",
"name": "[concat(parameters('storageNameDest'), '/default')]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageNameDest'))]"
],
"properties": {
"changeFeed": {
"enabled": "true"
},
"isVersioningEnabled": "true"
}
}
]
}
],
"outputs": {}
}
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageNameSrc": {
"type": "string",
"metadata": {
"description": "The source storage account name."
}
},
"storageNameDest": {
"type": "string",
"metadata": {
"description": "The dest storage account name."
}
},
"containerName": {
"type": "string",
"metadata": {
"description": "The container name to use in the source/dest accounts."
}
}
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts/ObjectReplicationPolicies",
"apiVersion": "2019-06-01",
"name" : "[concat(parameters('storageNameDest'), '/default')]",
"properties": {
"sourceAccount": "[parameters('storageNameSrc')]",
"destinationAccount": "[parameters('storageNameDest')]",
"rules": [
{
"sourceContainer": "[parameters('containerName')]",
"destinationContainer": "[parameters('containerName')]",
"filters": {
//Any prefixMatch filters here
}
}
]
}
}
]
}
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"policyId" : {
"type" : "string"
},
"ruleId" : {
"type" : "string"
},
"storageNameSrc": {
"type": "string",
"metadata": {
"description": "The source storage account name."
}
},
"storageNameDest": {
"type": "string",
"metadata": {
"description": "The dest storage account name."
}
},
"containerName": {
"type": "string",
"metadata": {
"description": "The container name to use in the source/dest accounts."
}
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts/ObjectReplicationPolicies",
"apiVersion": "2019-06-01",
"name": "[concat(parameters('storageNameSrc'), '/', parameters('policyId'))]",
"properties": {
"policyId": "[parameters('policyId')]",
"sourceAccount": "[parameters('storageNameSrc')]",
"destinationAccount": "[parameters('storageNameDest')]",
"rules": [
{
"ruleId": "[parameters('ruleId')]",
"sourceContainer": "[parameters('containerName')]",
"destinationContainer": "[parameters('containerName')]",
"filters": {
//Any prefixMatch filters here
}
}
]
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment