Skip to content

Commit c8935c2

Browse files
Merge pull request #113365 from tamram/tamram-0429
object replication
2 parents 0143bba + ad399b1 commit c8935c2

File tree

6 files changed

+430
-2
lines changed

6 files changed

+430
-2
lines changed

articles/storage/blobs/TOC.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@
165165
- name: Change feed
166166
href: storage-blob-change-feed.md
167167
- name: Point-in-time restore
168-
href: point-in-time-restore-overview.md
168+
href: point-in-time-restore-overview.md
169+
- name: Object replication
170+
href: object-replication-overview.md
169171
- name: Access and performance tiers
170172
items:
171173
- name: Access tiers
@@ -398,7 +400,9 @@
398400
- name: Process change feed logs
399401
href: storage-blob-change-feed-how-to.md
400402
- name: Enable point-in-time restore
401-
href: point-in-time-restore-manage.md
403+
href: point-in-time-restore-manage.md
404+
- name: Configure object replication
405+
href: object-replication-configure.md
402406
- name: Manage disaster recovery
403407
items:
404408
- name: Check the Last Sync Time property
22.1 KB
Loading
26.6 KB
Loading
71.8 KB
Loading
Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
---
2+
title: Configure object replication (preview)
3+
titleSuffix: Azure Storage
4+
description: Learn how to configure object replication to asynchronously copy block blobs from a container in one storage account to another.
5+
services: storage
6+
author: tamram
7+
8+
ms.service: storage
9+
ms.topic: how-to
10+
ms.date: 05/20/2020
11+
ms.author: tamram
12+
ms.subservice: blobs
13+
---
14+
15+
# Configure object replication for block blobs (preview)
16+
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).
18+
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.
20+
21+
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.
22+
23+
## Create a replication policy and rules
24+
25+
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).
26+
27+
Also, make sure that you have registered for the following feature previews:
28+
29+
- [Object replication (preview)](object-replication-overview.md)
30+
- [Blob versioning (preview)](versioning-overview.md)
31+
- [Change feed support in Azure Blob Storage (Preview)](storage-blob-change-feed.md)
32+
33+
# [Azure portal](#tab/portal)
34+
35+
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. Also, enabled blob versioning and change feed on the source account, and enable blob versioning on the destination account.
36+
37+
To create a replication policy in the Azure portal, follow these steps:
38+
39+
1. Navigate to the source storage account in the Azure portal.
40+
1. Under **Settings**, select **Object replication**.
41+
1. Select **Set up replication**.
42+
1. Select the destination subscription and storage account.
43+
1. In the **Container pairs** section, select a source container from the source account, and a destination container from the destination account. You can create up to 10 container pairs per replication policy.
44+
45+
The following image shows a set of replication rules.
46+
47+
:::image type="content" source="media/object-replication-configure/configure-replication-policy.png" alt-text="Screenshot showing replication rules in Azure portal":::
48+
49+
1. If desired, specify one or more filters to copy only blobs that match a prefix pattern. For example, if you specify a prefix `b`, only blobs whose name begin with that letter are replicated. You can specify a virtual directory as part of the prefix.
50+
51+
The following image shows filters that restrict which blobs are copied as part of a replication rule.
52+
53+
:::image type="content" source="media/object-replication-configure/configure-replication-copy-prefix.png" alt-text="Screenshot showing filters for a replication rule":::
54+
55+
1. By default, the copy scope is set to copy only new objects. To copy all objects in the container or to copy objects starting from a custom date and time, select the **change** link and configure the copy scope for the container pair.
56+
57+
The following image shows a custom copy scope.
58+
59+
:::image type="content" source="media/object-replication-configure/configure-replication-copy-scope.png" alt-text="Screenshot showing custom copy scope for object replication":::
60+
61+
1. Select **Save and apply** to create the replication policy and start replicating data.
62+
63+
# [PowerShell](#tab/powershell)
64+
65+
To create a replication policy with PowerShell, first install version [2.0.1-preview](https://www.powershellgallery.com/packages/Az.Storage/2.0.1-preview) of the Az.Storage PowerShell module. Follow these steps to install the preview module:
66+
67+
1. Uninstall any previous installations of Azure PowerShell from Windows using the **Apps & features** setting under **Settings**.
68+
69+
1. Make sure that you have the latest version of PowerShellGet installed. Open a Windows PowerShell window, and run the following command to install the latest version:
70+
71+
```powershell
72+
Install-Module PowerShellGet –Repository PSGallery –Force
73+
```
74+
75+
Close and reopen the PowerShell window after installing PowerShellGet.
76+
77+
1. Install the latest version of Azure PowerShell:
78+
79+
```powershell
80+
Install-Module Az –Repository PSGallery –AllowClobber
81+
```
82+
83+
1. Install the Az.Storage preview module:
84+
85+
```powershell
86+
Install-Module Az.Storage -Repository PSGallery -RequiredVersion 2.0.1-preview -AllowPrerelease -AllowClobber -Force
87+
```
88+
89+
For more information about installing Azure PowerShell, see [Install Azure PowerShell with PowerShellGet](/powershell/azure/install-az-ps).
90+
91+
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:
92+
93+
```powershell
94+
# Sign in to your Azure account.
95+
Connect-AzAccount
96+
97+
# Set variables.
98+
$rgName = "<resource-group>"
99+
$srcAccountName = "<source-storage-account>"
100+
$destAccountName = "<destination-storage-account>"
101+
$srcContainerName1 = "source-container1"
102+
$destContainerName1 = "dest-container1"
103+
$srcContainerName2 = "source-container2"
104+
$destContainerName2 = "dest-container2"
105+
106+
# Enable blob versioning and change feed on the source account.
107+
Update-AzStorageBlobServiceProperty -ResourceGroupName $rgname `
108+
-StorageAccountName $srcAccountName `
109+
-EnableChangeFeed $true `
110+
-IsVersioningEnabled $true
111+
112+
# Enable blob versioning on the destination account.
113+
Update-AzStorageBlobServiceProperty -ResourceGroupName $rgname `
114+
-StorageAccountName $destAccountName `
115+
-IsVersioningEnabled $true
116+
117+
# List the service properties for both accounts.
118+
Get-AzStorageBlobServiceProperty -ResourceGroupName $rgname `
119+
-StorageAccountName $srcAccountName
120+
Get-AzStorageBlobServiceProperty -ResourceGroupName $rgname `
121+
-StorageAccountName $destAccountName
122+
123+
# Create containers in the source and destination accounts.
124+
Get-AzStorageAccount -ResourceGroupName $rgname -StorageAccountName $srcAccountName |
125+
New-AzStorageContainer $srcContainerName1
126+
Get-AzStorageAccount -ResourceGroupName $rgname -StorageAccountName $destAccountName |
127+
New-AzStorageContainer $destContainerName1
128+
Get-AzStorageAccount -ResourceGroupName $rgname -StorageAccountName $srcAccountName |
129+
New-AzStorageContainer $srcContainerName2
130+
Get-AzStorageAccount -ResourceGroupName $rgname -StorageAccountName $destAccountName |
131+
New-AzStorageContainer $destContainerName2
132+
133+
# Define replication rules for each container.
134+
$rule1 = New-AzStorageObjectReplicationPolicyRule -SourceContainer $srcContainerName1 `
135+
-DestinationContainer $destContainerName1 `
136+
-PrefixMatch b
137+
$rule2 = New-AzStorageObjectReplicationPolicyRule -SourceContainer $srcContainerName2 `
138+
-DestinationContainer $destContainerName2 `
139+
-MinCreationTime 2020-05-10T00:00:00Z
140+
141+
# Create the replication policy on the destination account.
142+
$destPolicy = Set-AzStorageObjectReplicationPolicy -ResourceGroupName $rgname `
143+
-StorageAccountName $destAccountName `
144+
-PolicyId default `
145+
-SourceAccount $srcAccountName `
146+
-Rule $rule1,$rule2
147+
148+
# Create the same policy on the source account.
149+
Set-AzStorageObjectReplicationPolicy -ResourceGroupName $rgname `
150+
-StorageAccountName $srcAccountName `
151+
-InputObject $destPolicy
152+
```
153+
154+
# [Azure CLI](#tab/azure-cli)
155+
156+
To create a replication policy with Azure CLI, first install the preview extension for Azure Storage.:
157+
158+
```azurecli
159+
az extension add -n storage-or-preview
160+
```
161+
162+
Next, sign in with your Azure credentials:
163+
164+
```azurecli
165+
az login
166+
```
167+
168+
Enable blob versioning on the source and destination storage accounts, and enable change feed on the source account. Remember to replace values in angle brackets with your own values:
169+
170+
```azurecli
171+
az storage blob service-properties update --resource-group <resource-group> \
172+
--account-name <source-storage-account> \
173+
--enable-versioning
174+
175+
az storage blob service-properties update --resource-group <resource-group> \
176+
--account-name <source-storage-account> \
177+
--enable-change-feed
178+
179+
az storage blob service-properties update --resource-group <resource-group> \
180+
--account-name <dest-storage-account> \
181+
--enable-versioning
182+
```
183+
184+
Create the source and destination containers in their respective storage accounts.
185+
186+
```azurecli
187+
az storage container create --account-name <source-storage-account> --name source-container3 --auth-mode login
188+
az storage container create --account-name <source-storage-account> --name source-container4 --auth-mode login
189+
190+
az storage container create --account-name <dest-storage-account> --name source-container3 --auth-mode login
191+
az storage container create --account-name <dest-storage-account> --name source-container4 --auth-mode login
192+
```
193+
194+
Create a new replication policy and associated rules on the destination account.
195+
196+
```azurecli
197+
az storage account or-policy create --account-name <dest-storage-account> \
198+
--resource-group <resource-group> \
199+
--source-account <source-storage-account> \
200+
--destination-account <dest-storage-account> \
201+
--source-container source-container3 \
202+
--destination-container dest-container3 \
203+
--min-creation-time '2020-05-10T00:00:00Z' \
204+
--prefix-match a
205+
206+
az storage account or-policy rule add --account-name <dest-storage-account> \
207+
--destination-container dest-container4 \
208+
--policy-id <policy-id> \
209+
--resource-group <resource-group> \
210+
--source-container source-container4 \
211+
--prefix-match b
212+
```
213+
214+
Create the policy on the source account using the policy ID.
215+
216+
```azurecli
217+
az storage account or-policy show --resource-group <resource-group> \
218+
--name <dest-storage-account> \
219+
--policy-id <policy-id> |
220+
--az storage account or-policy create --resource-group <resource-group> \
221+
--name <source-storage-account> \
222+
--policy "@-"
223+
```
224+
225+
---
226+
227+
## Remove a replication policy
228+
229+
To remove a replication policy and its associated rules, use Azure portal, PowerShell, or CLI.
230+
231+
# [Azure portal](#tab/portal)
232+
233+
To remove a replication policy in the Azure portal, follow these steps:
234+
235+
1. Navigate to the source storage account in the Azure portal.
236+
1. Under **Settings**, select **Object replication**.
237+
1. Click the **More** button next to the policy name.
238+
1. Select **Delete Rules**.
239+
240+
# [PowerShell](#tab/powershell)
241+
242+
To remove a replication policy, delete the policy from both the source account and the destination account. Deleting the policy also deletes any rules associated with it.
243+
244+
```powershell
245+
Get-AzStorageObjectReplicationPolicy -ResourceGroupName $rgname `
246+
-StorageAccountName $destAccountName |
247+
Remove-AzStorageObjectReplicationPolicy
248+
Get-AzStorageObjectReplicationPolicy -ResourceGroupName $rgname `
249+
-StorageAccountName $srcAccountName |
250+
Remove-AzStorageObjectReplicationPolicy
251+
```
252+
253+
# [Azure CLI](#tab/azure-cli)
254+
255+
To remove a replication policy, delete the policy from both the source account and the destination account. Deleting the policy also deletes any rules associated with it.
256+
257+
```azurecli
258+
az storage account or-policy delete \
259+
--policy-id $policyid \
260+
--account-name <source-storage-account> \
261+
--resource-group <resource-group>
262+
263+
az storage account or-policy delete \
264+
--policy-id $policyid \
265+
--account-name <dest-storage-account> \
266+
--resource-group <resource-group>
267+
```
268+
269+
---
270+
271+
## Next steps
272+
273+
- [Object replication overview (preview)](object-replication-overview.md)

0 commit comments

Comments
 (0)