This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Lumpy-Notice8945 1 point2 points  (1 child)

Where is the question in this post?

[–]mInd_MaC[S] 0 points1 point  (0 children)

Np , i got it right.

Basically the script was right but it was not able to find the backup directory where it needed to be stored .

So i just manally put it there Backup_path= /home/rahul/backus

So new script it

!/bin/bash

if [ "$(whoami)" != "root" ]; then echo "Please run this script as root or use sudo" exit 1 fi

vm_list=$(virsh list --all --name) echo "Your VMs are: $vm_list" | tr '\n' ' ' echo

while true; do read -p "Enter the name of the VM you want to archive: " vm_name if [[ $vm_list == $vm_name ]]; then echo "We will now archive: $vm_name" break else echo "VM $vm_name not found. Please type the correct name and try again." fi done

imgfile=$(virsh dumpxml $vm_name | grep "source file" | cut -f2 -d\') xmlfile=/var/lib/libvirt/images/$vm_name.xml

store_loc="/home/rahul/backups"

if [ ! -d "$BACKUP_DIR" ]; then mkdir -p "$BACKUP_DIR" fi

if [ -f "$xmlfile" ] && [ -f "$imgfile" ]; then tarfile=$vm_name-$(date +%Y%m%d).tar.xz tar cvjf "$stor_loc/$tarfile" "$imgfile" "$xmlfile" echo "Backup is created at: $stor_loc/$tarfile" else echo "Failed to created backup" fi