13,420
edits
Changes
no edit summary
read -p "Backup all VMs? (y|n):" answer # prompt if all VMs to be backed-up
if [ "$answer" = "y" ] # Backup all VMs if answer is yes<br>
then
for num in 1 2 3 # Determinant loop for 3 arguments: 1, 2, and 3<br> do<br> echo "Backing up VM #$num"<br> gzip < /var/lib/libvirt/images/centos$num.img > /root/centos$num.img.backup.gz<br><br> echo "VM #$num BACKUP DONE" done<br><br>elif [ "$answer" = "n" ]<br><br>then<br> read -p "Which VM should be backed up? (1/2/3): " numanswer<br> until echo $numanswer | grep "^[123]$" >> /dev/null # Look for match of single digit: 1,2, or 3<br> do<br> read -p "Invalid Selection. Select 1, 2, or 3: " numanswer<br>
done<br>
fi