Skip to content

Commit acb1718

Browse files
committed
Updating CLI restore disks doc
1 parent 840af0a commit acb1718

File tree

1 file changed

+133
-44
lines changed

1 file changed

+133
-44
lines changed

articles/backup/tutorial-restore-disk.md

Lines changed: 133 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,43 @@ az backup recoverypoint list \
5252

5353
## Restore a VM disk
5454

55-
To restore your disk from the recovery point, you first create an Azure storage account. This storage account is used to store the restored disk. In additional steps, the restored disk is used to create a VM.
55+
> [!IMPORTANT]
56+
> It is very strongly recommended to use Az CLI version 2.0.74 or later to get all the benefits of a quick restore including managed disk restore. It is best if user always uses the latest version.
57+
58+
### Managed disk restore
59+
60+
If the backed up VM has managed disks and if the intent is to restore managed disks from the recovery point, you first provide an Azure storage account. This storage account is used to store the VM configuration and the deployment template that can be later used to deploy the VM from the restored disks. Then, you also provide a target resource group for the managed disks to be restored into.
61+
62+
1. To create a storage account, use [az storage account create](https://docs.microsoft.com/cli/azure/storage/account?view=azure-cli-latest#az-storage-account-create). The storage account name must be all lowercase, and be globally unique. Replace *mystorageaccount* with your own unique name:
63+
64+
```azurecli-interactive
65+
az storage account create \
66+
--resource-group myResourceGroup \
67+
--name mystorageaccount \
68+
--sku Standard_LRS
69+
```
70+
71+
2. Restore the disk from your recovery point with [az backup restore restore-disks](https://docs.microsoft.com/cli/azure/backup/restore?view=azure-cli-latest#az-backup-restore-restore-disks). Replace *mystorageaccount* with the name of the storage account you created in the preceding command. Replace *myRecoveryPointName* with the recovery point name you obtained in the output from the previous [az backup recoverypoint list](https://docs.microsoft.com/cli/azure/backup/recoverypoint?view=azure-cli-latest#az-backup-recoverypoint-list) command. ***Also provide the target resource group to which the managed disks are restored into***.
72+
73+
```azurecli-interactive
74+
az backup restore restore-disks \
75+
--resource-group myResourceGroup \
76+
--vault-name myRecoveryServicesVault \
77+
--container-name myVM \
78+
--item-name myVM \
79+
--storage-account mystorageaccount \
80+
--rp-name myRecoveryPointName
81+
--target-resource-group targetRG
82+
```
83+
84+
> [!WARNING]
85+
> If target-resource-group is not provided then the managed disks will be restored as unmanaged disks to the given storage account. This will have significant consequences to the restore time since the time taken to restore the disks entirely depends on the given storage account.
86+
87+
### Unmanaged disks restore
88+
89+
If the backed up VM has unmanaged disks and if the intent is to restore disks from the recovery point, you first provide an Azure storage account. This storage account is used to store the VM configuration and the deployment template that can be later used to deploy the VM from the restored disks. By default, the unmanaged disks will be restored to their original storage accounts. If user wishes to restore all unmanaged disks to one single place, then the given storage account can also be used as a staging location for those disks too.
90+
91+
In additional steps, the restored disk is used to create a VM.
5692
5793
1. To create a storage account, use [az storage account create](https://docs.microsoft.com/cli/azure/storage/account?view=azure-cli-latest#az-storage-account-create). The storage account name must be all lowercase, and be globally unique. Replace *mystorageaccount* with your own unique name:
5894
@@ -75,6 +111,19 @@ To restore your disk from the recovery point, you first create an Azure storage
75111
--rp-name myRecoveryPointName
76112
```
77113
114+
As mentioned above, the unmanaged disks will be restored to their original storage account. This provides the best restore performance. But if all unmanaged disks need to be restored to given storage account, then use the relevant flag as shown below.
115+
116+
```azurecli-interactive
117+
az backup restore restore-disks \
118+
--resource-group myResourceGroup \
119+
--vault-name myRecoveryServicesVault \
120+
--container-name myVM \
121+
--item-name myVM \
122+
--storage-account mystorageaccount \
123+
--rp-name myRecoveryPointName
124+
--restore-to-staging-storage-account
125+
```
126+
78127
## Monitor the restore job
79128
80129
To monitor the status of restore job, use [az backup job list](https://docs.microsoft.com/cli/azure/backup/job?view=azure-cli-latest#az-backup-job-list):
@@ -96,65 +145,105 @@ a0a8e5e6 Backup Completed myvm 2017-09-19T03:09:21 0:15:26
96145
fe5d0414 ConfigureBackup Completed myvm 2017-09-19T03:03:57 0:00:31.191807
97146
```
98147

99-
When the *Status* of the restore job reports *Completed*, the disk has been restored to the storage account.
148+
When the *Status* of the restore job reports *Completed*, the necessary information (VM configuration and the deployment template) has been restored to the storage account.
100149

101-
## Convert the restored disk to a Managed Disk
150+
## Create a VM from the restored disk
102151

103-
The restore job creates an unmanaged disk. In order to create a VM from the disk, it must first be converted to a managed disk.
152+
The final step is to create a VM from the restored disks. You can use the deployment template downloaded to the given storage account to create the VM.
104153

105-
1. Obtain the connection information for your storage account with [az storage account show-connection-string](https://docs.microsoft.com/cli/azure/storage/account?view=azure-cli-latest#az-storage-account-show-connection-string). Replace *mystorageaccount* with the name of your storage account as follows:
154+
### Fetch the Job details
106155

107-
```azurecli-interactive
108-
export AZURE_STORAGE_CONNECTION_STRING=$( az storage account show-connection-string \
109-
--resource-group myResourceGroup \
110-
--output tsv \
111-
--name mystorageaccount )
112-
```
156+
The resultant job details give the template URI that can be queried and deployed. Use the job show command to get more details for the triggered restored job.
113157

114-
2. Your unmanaged disk is secured in the storage account. The following commands get information about your unmanaged disk and create a variable named *uri* that is used in the next step when you create the Managed Disk.
158+
```azurecli-interactive
159+
az backup job show \
160+
-v myRecoveryServicesVault \
161+
-g myResourceGroup \
162+
-n 1fc2d55d-f0dc-4ca6-ad48-aca0fe5d0414
163+
```
115164

116-
```azurecli-interactive
117-
container=$(az storage container list --query [0].name -o tsv)
118-
blob=$(az storage blob list --container-name $container --query [0].name -o tsv)
119-
uri=$(az storage blob url --container-name $container --name $blob -o tsv)
120-
```
165+
The output of this query will give all details but we are interested only in the storage account contents. We can use the [query capability](https://docs.microsoft.com/cli/azure/query-azure-cli?view=azure-cli-latest) of Azure CLI to fetch the relevant details
121166

122-
3. Now you can create a Managed Disk from your recovered disk with [az disk create](https://docs.microsoft.com/cli/azure/disk?view=azure-cli-latest#az-disk-create). The *uri* variable from the preceding step is used as the source for your Managed Disk.
167+
```azurecli-interactive
168+
az backup job show \
169+
-v myRecoveryServicesVault \
170+
-g myResourceGroup \
171+
-n 1fc2d55d-f0dc-4ca6-ad48-aca0fe5d0414 \
172+
--query properties.extendedInfo.propertyBag
173+
174+
{
175+
"Config Blob Container Name": "myVM-daa1931199fd4a22ae601f46d8812276",
176+
"Config Blob Name": "config-myVM-1fc2d55d-f0dc-4ca6-ad48-aca0fe5d0414.json",
177+
"Config Blob Uri": "https://mystorageaccount.blob.core.windows.net/myVM-daa1931199fd4a22ae601f46d8812276/config-appvm8-1fc2d55d-f0dc-4ca6-ad48-aca0519c0232.json",
178+
"Job Type": "Recover disks",
179+
"Recovery point time ": "12/25/2019 10:07:11 PM",
180+
"Target Storage Account Name": "mystorageaccount",
181+
"Target resource group": "mystorageaccountRG",
182+
"Template Blob Uri": "https://mystorageaccount.blob.core.windows.net/myVM-daa1931199fd4a22ae601f46d8812276/azuredeploy1fc2d55d-f0dc-4ca6-ad48-aca0519c0232.json"
183+
}
184+
```
123185

124-
```azurecli-interactive
125-
az disk create \
126-
--resource-group myResourceGroup \
127-
--name myRestoredDisk \
128-
--source $uri
129-
```
186+
### Fetch the deployment template
130187

131-
4. As you now have a Managed Disk from your restored disk, clean up the unmanaged disk and storage account with [az storage account delete](/cli/azure/storage/account?view=azure-cli-latest#az-storage-account-delete). Replace *mystorageaccount* with the name of your storage account as follows:
188+
The template is not directly accessible since it is under a customer's storage account and the given container. We need the complete URL (along with a temporary SAS token) to access this template.
132189

133-
```azurecli-interactive
134-
az storage account delete \
135-
--resource-group myResourceGroup \
136-
--name mystorageaccount
137-
```
190+
First, extract the template blob Uri from job details
138191

139-
## Create a VM from the restored disk
192+
```azurecli-interactive
193+
az backup job show \
194+
-v myRecoveryServicesVault \
195+
-g myResourceGroup \
196+
-n 1fc2d55d-f0dc-4ca6-ad48-aca0fe5d0414 \
197+
--query properties.extendedInfo.propertyBag."""Template Blob Uri"""
140198
141-
The final step is to create a VM from the Managed Disk.
199+
"https://mystorageaccount.blob.core.windows.net/myVM-daa1931199fd4a22ae601f46d8812276/azuredeploy1fc2d55d-f0dc-4ca6-ad48-aca0519c0232.json"
200+
```
142201

143-
1. Create a VM from your Managed Disk with [az vm create](/cli/azure/vm?view=azure-cli-latest#az-vm-create) as follows:
202+
The template blob Uri will be of this format and extract the template name
144203

145-
```azurecli-interactive
146-
az vm create \
147-
--resource-group myResourceGroup \
148-
--name myRestoredVM \
149-
--attach-os-disk myRestoredDisk \
150-
--os-type linux
151-
```
204+
```https
205+
https://<storageAccountName.blob.core.windows.net>/<containerName>/<templateName>
206+
```
152207

153-
2. To confirm that your VM has been created from your recovered disk, list the VMs in your resource group with [az vm list](/cli/azure/vm?view=azure-cli-latest#az-vm-list) as follows:
208+
So, the template name from the above example will be ```azuredeploy1fc2d55d-f0dc-4ca6-ad48-aca0519c0232.json``` and the container name is ```myVM-daa1931199fd4a22ae601f46d8812276```
154209

155-
```azurecli-interactive
156-
az vm list --resource-group myResourceGroup --output table
157-
```
210+
Now get the SAS token for this container and template as detailed [here](https://docs.microsoft.com/azure/azure-resource-manager/templates/secure-template-with-sas-token?tabs=azure-cli#provide-sas-token-during-deployment)
211+
212+
```azurecli-interactive
213+
expiretime=$(date -u -d '30 minutes' +%Y-%m-%dT%H:%MZ)
214+
connection=$(az storage account show-connection-string \
215+
--resource-group mystorageaccountRG \
216+
--name {your-unique-name} \
217+
--query connectionString)
218+
token=$(az storage blob generate-sas \
219+
--container-name myVM-daa1931199fd4a22ae601f46d8812276 \
220+
--name azuredeploy1fc2d55d-f0dc-4ca6-ad48-aca0519c0232.json \
221+
--expiry $expiretime \
222+
--permissions r \
223+
--output tsv \
224+
--connection-string $connection)
225+
url=$(az storage blob url \
226+
--container-name myVM-daa1931199fd4a22ae601f46d8812276 \
227+
--name azuredeploy1fc2d55d-f0dc-4ca6-ad48-aca0519c0232.json \
228+
--output tsv \
229+
--connection-string $connection)
230+
```
231+
232+
### Deploy the template to create the VM
233+
234+
Now deploy the template to create the VM as explained [here](https://docs.microsoft.com/azure/azure-resource-manager/templates/deploy-cli).
235+
236+
```azurecli-interactive
237+
az group deployment create \
238+
--resource-group ExampleGroup \
239+
--template-uri $url?$token
240+
```
241+
242+
To confirm that your VM has been created from your recovered disk, list the VMs in your resource group with [az vm list](/cli/azure/vm?view=azure-cli-latest#az-vm-list) as follows:
243+
244+
```azurecli-interactive
245+
az vm list --resource-group myResourceGroup --output table
246+
```
158247

159248
## Next steps
160249

0 commit comments

Comments
 (0)