Bash Example of
Calculating the Size Needed To Store the Backup File
This example shows how to invoke
curl
from a bash script
to collect the information you use to calculate the size needed to store a backup file of
the instance. This example depends on certain variables that specify
the address of the
instance and credentials to access the
appliance.recovery
API.
For simplicity, the variables are hard-coded at the start of the bash script. #!/bin/bash ##### EDITABLE BY USER to specify vCenter Server instance and credentials. ##### VC_ADDRESS=vcsa_ip VC_USER=sso_user VC_PASSWORD=sso_pass ############################ # Authenticate with basic credentials. curl -u "$VC_USER:$VC_PASSWORD" \ -X POST \ -k --cookie-jar cookies.txt \ "https://$VC_ADDRESS/api/com/vmware/cis/session" echo '' # Issue a request to list the backup file parts. curl -k -s --cookie cookies.txt \ -H 'Accept:application/json' \ "https://$VC_ADDRESS/api/appliance/recovery/backup/parts" \ >response.txt # Extract IDs of backup file parts. IDs=$(awk '{for (s=$0; match(s,/"id":"\w+"/); s=substr(s,RSTART+RLENGTH)) \ print substr(s,RSTART+6,RLENGTH-7);}' \ response.txt) # Request sizes of parts. echo Backup space required, by part ID: let "total=0" for ID in $IDs ; do curl -k -s --cookie cookies.txt \ -H 'Accept:application/json' \ "https://$VC_ADDRESS/api/appliance/recovery/backup/parts/$ID" \ >response.txt size=$(awk '{if (match($0,/"value":\w+/)) \ print substr($0,RSTART+8,RLENGTH-8);}' \ response.txt) printf " %-8s - %5dMB\n" "$ID" "$size" let "total += $size" done echo '' echo "Complete backup file size: ${total}MB" # Clean up temporary files. echo '' rm -f response.txt rm -f cookies.txt