Changes

Jump to: navigation, search

OPS235 Lab 2 - CentOS7

88 bytes added, 08:44, 21 April 2015
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
&nbsp;for num in 1 2 3 # Determinant loop for 3 arguments: 1, 2, and 3<br>&nbsp;do<br>&nbsp;&nbsp;echo "Backing up VM #$num"<br>&nbsp;&nbsp;gzip < /var/lib/libvirt/images/centos$num.img > /root/centos$num.img.backup.gz<br><br>&nbsp;&nbsp;echo "VM #$num BACKUP DONE"&nbsp;done<br><br>elif [ "$answer" = "n" ]<br><br>then<br>&nbsp;read -p "Which VM should be backed up? (1/2/3): " numanswer<br>&nbsp;until echo $numanswer | grep "^[123]$" >> /dev/null # Look for match of single digit: 1,2, or 3<br>&nbsp;do<br>&nbsp;&nbsp;read -p "Invalid Selection. Select 1, 2, or 3: " numanswer<br>
&nbsp;done<br>
elif [ "$answer" = "n" ]then&nbsp;read -p "Which VM should be backed up? (1/2/3): " numanswer&nbsp;until echo $numanswer | grep "^[123]$" >> /dev/null # Look for match of single digit: 1,2, or 3&nbsp;do&nbsp;&nbsp;read -p "Invalid Selection. Select 1, 2, or 3: " numanswer&nbsp;done&nbsp;echo "Backing up VM #$numanswer"<br>&nbsp;gzip < /var/lib/libvirt/images/centos$numanswer.img > /root/centos$numanswer.img.backup.gz<br><br>&nbsp;echo "VM #$numanswer BACKUP DONE":<br>else<br>&nbsp;echo "Invalid Selection... Aborting program"<br>&nbsp;exit 2<br>
fi
13,420
edits

Navigation menu