Difference between revisions of "Az cli backups"
Jump to navigation
Jump to search
Line 15: | Line 15: | ||
``` | ``` | ||
#!/bin/bash | #!/bin/bash | ||
− | set - | + | set -eux |
rg_name=MY-RGRP | rg_name=MY-RGRP | ||
ttl=43200 | ttl=43200 | ||
Line 24: | Line 24: | ||
azd0-foo_datadisk01 | azd0-foo_datadisk01 | ||
) | ) | ||
+ | |||
+ | jq -h || sudo apt install -y jq | ||
main(){ | main(){ | ||
for disk_name in "${disks[@]}"; do | for disk_name in "${disks[@]}"; do | ||
− | file_name="${disk_name}__${rg_name} | + | file_name="${disk_name}__${rg_name}.vhd" |
echo Exporting disk $file_name in 10 seconds; sleep 10 | echo Exporting disk $file_name in 10 seconds; sleep 10 | ||
− | r=$(az disk grant-access --duration-in-seconds $ttl --access-level Read --name $disk_name --resource-group $rg_name) url=$(echo $r | jq '.accessSas') | + | r=$(az disk grant-access --duration-in-seconds $ttl --access-level Read --name $disk_name --resource-group $rg_name) url=$(echo $r | jq -r '.accessSas') |
echo Downloading disk vhd for $file_name from $url in 10 seconds; sleep 10 | echo Downloading disk vhd for $file_name from $url in 10 seconds; sleep 10 | ||
+ | echo Downloading now | ||
az storage blob download -f ${file_name} --blob-url ${url} | az storage blob download -f ${file_name} --blob-url ${url} | ||
+ | tar -czvf ${file_name}.tgz ${file_name} | ||
+ | rm ${file_name} | ||
done | done | ||
} | } | ||
+ | |||
+ | main | ||
``` | ``` |
Latest revision as of 19:57, 14 September 2022
az disk grant-access --duration-in-seconds 86400 --access-level Read --name azd0-foo_OsDisk_1 --resource-group MY-RESOURCE-GROUP
Download
az login --scope https://management.core.windows.net//.default url="https://md-hdd-..myurlfrom-grant-access" file_name=azd0-foo.vhd az storage blob download -f ${file_name} --blob-url ${url}
Backup disks via array in MY-RGRP resource group
#!/bin/bash set -eux rg_name=MY-RGRP ttl=43200 ttl=86400 disks=( azd0-foo_osdisk01 azd0-foo_datadisk01 ) jq -h || sudo apt install -y jq main(){ for disk_name in "${disks[@]}"; do file_name="${disk_name}__${rg_name}.vhd" echo Exporting disk $file_name in 10 seconds; sleep 10 r=$(az disk grant-access --duration-in-seconds $ttl --access-level Read --name $disk_name --resource-group $rg_name) url=$(echo $r | jq -r '.accessSas') echo Downloading disk vhd for $file_name from $url in 10 seconds; sleep 10 echo Downloading now az storage blob download -f ${file_name} --blob-url ${url} tar -czvf ${file_name}.tgz ${file_name} rm ${file_name} done } main