-
Notifications
You must be signed in to change notification settings - Fork 9
/
BackupLinuxVM.azcli
38 lines (27 loc) · 1.42 KB
/
BackupLinuxVM.azcli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$recoveryServicesVaultName = "mac-rsv"
$resourceGroupName = "mac-backup-rg"
$virtualMachineName = "mac-ubuntu01VM"
$location = "westeurope"
$adminName = "macadmin"
# Create the Resource Group
az group create --name $resourceGroupName --location $location
# Create a Virtual Machine
az vm create --resource-group $resourceGroupName --name $virtualMachineName --image UbuntuLTS --admin-username $adminName --generate-ssh-keys
# open up port 80
az vm open-port --port 80 --resource-group $resourceGroupName --name $virtualMachineName
#get public IP
az vm show --resource-group $resourceGroupName --name $virtualMachineName -d --query [publicIps] --o tsv
#login to VM
ssh macadmin@publicIpAddress
# update packages
sudo apt-get -y update
# install NGINX
sudo apt-get -y install nginx
#create recovery vault
az backup vault create --resource-group $resourceGroupName --name $recoveryServicesVaultName --location $location
# enable backup
az backup protection enable-for-vm --resource-group $resourceGroupName --vault-name $recoveryServicesVaultName --vm $virtualMachineName --policy-name DefaultPolicy
# initial backup
az backup protection backup-now --resource-group $resourceGroupName --vault-name $recoveryServicesVaultName --container-name $virtualMachineName --item-name $virtualMachineName --retain-until 18-10-2019
# watch backup
az backup job list --resource-group $resourceGroupName --vault-name $recoveryServicesVaultName --output table