715
edits
Changes
no edit summary
<pre>
else:
backupAll=input("Do you wish to backup all VMs? (y | n) ")
</pre>
=== Asking the user which VM they wish to backup, and performing the backup ===
If the user selected no above, we need to know what VM they wish to backup. We will prompt again and use a nested if statement to check their response. Then, perform the desired backup.
<pre>
if backupAll == "n":
backupVM=input("What VM do you wish to backup? ")
if backupVM == "centos1":
print("Backing up centos1")
os.system("virsh dumpxml centos1 > /home/jmcarman/backups/centos1.xml")
os.system("gzip < /var/lib/libvirt/images/centos1.qcow2 > /home/jmcarman/backups/centos1.qcow2.gz")
elif backupVM == "centos2":
# Repeat above steps with replacing centos1 with centos2
</pre>
Using the above sample, add the steps to backup centos2 or centos3 if appropriate.
=== Error checking ===
If the user submits an invalid VM name (not centos1, centos2 or centos3) we should generate an error and exit.
<pre>
else:
sys.exit("Invalid choice, your VM options are centos1, centos2, centos3")
</pre>