Skip to content

Commit e29bdee

Browse files
committed
added PS example
1 parent f4ae903 commit e29bdee

File tree

2 files changed

+58
-61
lines changed

2 files changed

+58
-61
lines changed

articles/storage/blobs/object-replication-configure.md

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@ author: tamram
77

88
ms.service: storage
99
ms.topic: how-to
10-
ms.date: 05/12/2020
10+
ms.date: 05/18/2020
1111
ms.author: tamram
1212
ms.subservice: blobs
1313
---
1414

1515
# Configure object replication (preview)
1616

17-
Object replication (preview) asynchronously copies block blobs between a source storage account and a destination account. The source and destination accounts may be in different regions. For more information about object replication, see [Object replication (preview)](object-replication-overview.md).
17+
Object replication (preview) asynchronously copies block blobs between a source storage account and a destination account. For more information about object replication, see [Object replication (preview)](object-replication-overview.md).
1818

19-
To use object replication, create a replication policy on the source account that specifies the destination account. Then add one or more replication rules to the policy. Replication rules specify the source and destination containers and determine which block blobs in those containers will be copied.
19+
When you configure object replication, you create a replication policy that specifies the source storage account and the destination account. A replication policy includes one or more rules that specify a source container and a destination container and indicate which block blobs in the source container will be replicated.
2020

2121
This article describes how to configure object replication for your storage account by using the Azure portal, PowerShell, or Azure CLI. You can also use one of the Azure Storage resource provider client libraries to configure object replication.
2222

2323
## Create a replication policy and rules
2424

2525
Before you configure object replication, create the source and destination storage accounts if they do not already exist. Both accounts must be general-purpose v2 storage accounts. For more information, see [Create an Azure Storage account](../common/storage-account-create.md).
2626

27-
Also create the source and destination containers in their respective storage accounts, if they do not already exist.
27+
# [Azure portal](#tab/portal)
28+
29+
Before you configure object replication in the Azure portal, create the source and destination containers in their respective storage accounts, if they do not already exist.
2830

29-
Finally, enable the following prerequisites:
31+
Next, make sure you have enabled the following prerequisites:
3032

3133
- [Change feed (preview)](storage-blob-change-feed.md) on the source account
3234
- [Blob versioning (preview)](versioning-overview.md) on the source and destination accounts
3335

34-
# [Azure portal](#tab/portal)
35-
36-
To create a replication policy and add replication rules in the Azure portal, follow these steps:
36+
To create a replication policy in the Azure portal, follow these steps:
3737

3838
1. Navigate to the source storage account in the Azure portal.
3939
1. Under **Settings**, select **Object replication**.
@@ -61,9 +61,7 @@ To create a replication policy and add replication rules in the Azure portal, fo
6161

6262
# [PowerShell](#tab/powershell)
6363

64-
### Install the preview module
65-
66-
To create a replication policy and add replication rules using PowerShell, first install version [1.14.1-preview](https://www.powershellgallery.com/packages/Az.Storage/1.14.1-preview) of the Az.Storage PowerShell module. Follow these steps to install the preview module:
64+
To create a replication policy with PowerShell, first install version [1.14.1-preview](https://www.powershellgallery.com/packages/Az.Storage/1.14.1-preview) of the Az.Storage PowerShell module. Follow these steps to install the preview module:
6765

6866
1. Uninstall any previous installations of Azure PowerShell from Windows using the **Apps & features** setting under **Settings**.
6967

@@ -73,7 +71,7 @@ To create a replication policy and add replication rules using PowerShell, first
7371
Install-Module PowerShellGet –Repository PSGallery –Force
7472
```
7573
76-
1. Close and reopen the PowerShell window after installing PowerShellGet.
74+
Close and reopen the PowerShell window after installing PowerShellGet.
7775
7876
1. Install the latest version of Azure PowerShell:
7977
@@ -89,15 +87,13 @@ To create a replication policy and add replication rules using PowerShell, first
8987
9088
For more information about installing Azure PowerShell, see [Install Azure PowerShell with PowerShellGet](/powershell/azure/install-az-ps).
9189
92-
### Configure replication policy and rules
93-
94-
Before running the example, use the Azure portal or an Azure Resource Manager template to enable blob versioning on the source and destination accounts.
90+
The following example shows how to create a replication policy on the source and destination accounts. Remember to replace values in angle brackets with your own values:
9591
9692
```powershell
9793
# Sign in to your Azure account.
9894
Connect-AzAccount
9995
100-
# Set resource group and account variables.
96+
# Set variables.
10197
$rgName = "<resource-group>"
10298
$srcAccountName = "<source-storage-account>"
10399
$destAccountName = "<destination-storage-account>"
@@ -106,62 +102,63 @@ $destContainerName1 = "dest-container1"
106102
$srcContainerName2 = "source-container2"
107103
$destContainerName2 = "dest-container2"
108104
109-
# Enable change feed on the source account.
110-
Update-AzStorageBlobServiceProperty -ResourceGroupName $rgName `
105+
# Enable blob versioning and change feed on the source account.
106+
Update-AzStorageBlobServiceProperty -ResourceGroupName $rgname `
111107
-StorageAccountName $srcAccountName `
112-
-EnableChangeFeed $true
108+
-EnableChangeFeed $true `
109+
-IsVersioningEnabled $true
110+
111+
# Enable blob versioning on the destination account.
112+
Update-AzStorageBlobServiceProperty -ResourceGroupName $rgname `
113+
-StorageAccountName $destAccountName `
114+
-IsVersioningEnabled $true
113115
114-
# View the service settings.
115-
Get-AzStorageBlobServiceProperty -ResourceGroupName $rgName `
116-
-StorageAccountName $accountName
116+
# List the service properties for both accounts.
117+
Get-AzStorageBlobServiceProperty -ResourceGroupName $rgname `
118+
-StorageAccountName $srcAccountName
119+
Get-AzStorageBlobServiceProperty -ResourceGroupName $rgname `
120+
-StorageAccountName $destAccountName
117121
118122
# Create new containers in the source and destination accounts.
119123
$srcAccount | New-AzStorageContainer $srcContainerName1
120124
$destAccount | New-AzStorageContainer $destContainerName1
121125
$srcAccount | New-AzStorageContainer $srcContainerName2
122126
$destAccount | New-AzStorageContainer $destContainerName2
123127
128+
# Create containers in the source and destination accounts.
129+
Get-AzStorageAccount -ResourceGroupName $rgname -StorageAccountName $srcAccountName |
130+
New-AzStorageContainer $srcContainerName1
131+
Get-AzStorageAccount -ResourceGroupName $rgname -StorageAccountName $destAccountName |
132+
New-AzStorageContainer $destContainerName1
133+
Get-AzStorageAccount -ResourceGroupName $rgname -StorageAccountName $srcAccountName |
134+
New-AzStorageContainer $srcContainerName2
135+
Get-AzStorageAccount -ResourceGroupName $rgname -StorageAccountName $destAccountName |
136+
New-AzStorageContainer $destContainerName2
137+
138+
# Define replication rules for each container.
139+
$rule1 = New-AzStorageObjectReplicationPolicyRule -SourceContainer $srcContainerName1 `
140+
-DestinationContainer $destContainerName1 `
141+
-PrefixMatch b
142+
$rule2 = New-AzStorageObjectReplicationPolicyRule -SourceContainer $srcContainerName2 `
143+
-DestinationContainer $destContainerName2 `
144+
-MinCreationTime 2020-05-10T00:00:00Z
145+
146+
# Create the replication policy on the destination account.
147+
$destPolicy = Set-AzStorageObjectReplicationPolicy -ResourceGroupName $rgname `
148+
-StorageAccountName $destAccountName `
149+
-PolicyId default `
150+
-SourceAccount $srcAccountName `
151+
-Rule $rule1,$rule2
152+
153+
# Create the same policy on the source account.
154+
Set-AzStorageObjectReplicationPolicy -ResourceGroupName $rgname `
155+
-StorageAccountName $srcAccountName `
156+
-InputObject $destPolicy
124157
```
125158

159+
# [Azure CLI](#tab/azure-cli)
126160

127-
128-
Create a new replication rule and specify the desired prefix and replication behavior for the objects, that existed prior to configuring object replication.
129-
130-
\$rule = New-AzStorageObjectReplicationPolicyRule -SourceContainer \<source container\> -DestinationContainer \<destination container\> -PrefixMatch \<desired prefix match\> -MinCreationTime (Get-Date).AddDays(-3)
131-
132-
For list of available parameters and their values, run Get-Help New-AzStorageObjectReplicationPolicyRule -Full and/or Get-Help New-AzStorageObjectReplicationPolicyRule -Examples.
133-
134-
Create a replication policy on the destination account and pass on the rule you created earlier.
135-
136-
Set-AzStorageObjectReplicationPolicy -ResourceGroupName \<resource group\> -StorageAccountName \<destination storage account\> -PolicyId default -SourceAccount \<source storage account\> -Rule \$rule
137-
138-
Retrieve the replication policy you created and enable object replication on the source account by adding the replication policy to it.
139-
140-
\$dstpolicy = Get-AzStorageObjectReplicationPolicy -ResourceGroupName \<resource group\> -StorageAccountName \<destination storage account\>
141-
142-
Set-AzStorageObjectReplicationPolicy -ResourceGroupName \<resource group\> -StorageAccountName \<source storage account\> -InputObject \$dstpolicy
143-
144-
Get details on the replication policy in effect on the destination account and its associated properties.
145-
146-
\$dstpolicy
147-
148-
\$dstpolicy.Rules
149-
150-
Get details on the replication policy in effect on the source account and its associated properties.
151-
152-
\$srcpolicy = Get-AzStorageObjectReplicationPolicy -ResourceGroupName \<resource group\> -StorageAccountName \<source storage account\>
153-
154-
\$srcpolicy
155-
156-
\$srcpolicy.Rules
157-
158-
When no longer needed, remove the replication policy from the source and destination accounts.
159-
160-
Get-AzStorageObjectReplicationPolicy -ResourceGroupName \<resource group\> -StorageAccountName \<destination storage account\> \| Remove-AzStorageObjectReplicationPolicy
161-
162-
Get-AzStorageObjectReplicationPolicy -ResourceGroupName \<resource group\> -StorageAccountName \<source storage account\> \| Remove-AzStorageObjectReplicationPolicy
163-
164-
# [Azure CLI](#tab/cli)
161+
To create a replication policy with Azure CLI, first install version [1.14.1-preview](https://www.powershellgallery.com/packages/Az.Storage/1.14.1-preview) of the Az.Storage PowerShell module. Follow these steps to install the preview module:
165162

166163
Refer to [Install the Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli?view=azure-cli-latest) article to install and import the preview module supporting object replication capability.
167164

articles/storage/blobs/object-replication-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ author: tamram
77

88
ms.service: storage
99
ms.topic: conceptual
10-
ms.date: 05/12/2020
10+
ms.date: 05/18/2020
1111
ms.author: tamram
1212
ms.subservice: blobs
1313
---

0 commit comments

Comments
 (0)