Installation
A step-by-step example is given below:1. #!/bin/bash2. set -euo pipefail3. IFS=$’\n\t’4. #Written By Arvind GK5. #Part 2 : To backup Second VM Disk6. This File name backup-vm-1st-disk.sh7. DOMAIN=”$1”8. UUID=$(sudo virsh dumpxml $DOMAIN | grep uuid | cut -d”>” -f2 | cut -d”<” -f1)9.10. DISK_LOCATION=$(sudo virsh domblklist “$DOMAIN” | grep hda | tr -s “ “ | cut -d” “ -f2-)11.12. DISK_LOCATION1=$(sudo virsh domblklist “$DOMAIN” | grep hdb| tr -s “ “ | cut -d” “ -f2-)13.14. # Export Borg encryption key , You can also modify this to using public and private key. Here I have user simple passphrase as example.15. export BORG_PASSPHRASE=”1234”16.17. # Export the rate-limited remote shell18. #export BORG_RSH=”/usr/local/bin/pv-wrapper ssh”19.20. Create the snapshot to a temp file on the Linux drive21.22. sudo virsh snapshot-create-as --domain $DOMAIN \23.24. tempsnap “Temporary snapshot used while backing up $DOMAIN” \ --disk-only --diskspec $DISK_LOCATION,file=”/img/$DOMAIN-tempsnap.qcow2” \ --atomic25.26. Commit the changes that took place in the Windows drive while27. Sync the virsh metadata with reality by deleting the metadata28. external image right now but that is not implemented yet)29.30. sudo virsh snapshot-delete “$DOMAIN” tempsnap --metadata31.32. (they have already been merged back into the original image) sudo rm -f “/img/$DOMAIN-tempsnap.qcow2” sudo rm -f “$DISK_LOCATION1”33.34. fi35. }36.37. Stupid hack: make a list of all the files we *don’t* want to save so we can exclude them from the backup38.39. find $(dirname “$DISK_LOCATION”) ! -type d ! -wholename “$DISK_LOCATION” | awk ‘{print “sh:” $0;}’ > iso-exclusions40. the --read-special flag tells borg to follow the symlink & read the block device directly41.42. Remove the temp file for the exclusions rm iso-exclusions || /bin/true43. if it already succeeded and this ensures all guest disk access is on44. Prune the backups on the server that are older than a certain date echo “Pruning old backups”45. borg prune -v --list /backup --prefix “$DOMAIN-” --keep-within=1m & wait || /bin/true46. echo “Done”