A script to export all inactive KVM/QEMU databases to the current directory. Thus, it works best if placed in the $PATH
Find a file
Gabriel Viso Carrera 7f99eae0e4 Sample run
2024-12-17 09:16:55 +11:00
kvm-export.sh Initial Commit 2024-12-17 09:02:33 +11:00
LICENSE Initial Commit 2024-12-17 09:02:33 +11:00
README.md Sample run 2024-12-17 09:16:55 +11:00

KVM Export

Script that exports the KVM/QEMU virtual machines to the current directory.

Usage

It works best if placed in the $PATH. It uses internally sudo, so it will prompt the user for authentication to get administrator privileges. This is because the virtual machines are in /var/lib/ and the system policy required administrator privileges in order to operate them.

It will create a folder per VM using the current date and the VM name.

Sample run:

$ kvm-export
Place your finger on the fingerprint reader
Processing machine 'almalinux9':
 - Configuration dump for machine 'almalinux9'
 - Compressing /var/lib/libvirt/images/almalinux9.qcow2
      into 2024-12-17-almalinux9/almalinux9.qcow2.gz
 - Changing file ownership of dir. 2024-12-17-almalinux9 to gvisoc
Done with machine 'almalinux9'
Processing machine 'barcas-lab':
 - Configuration dump for machine 'barcas-lab'
 - Compressing /var/lib/libvirt/images/barcas-lab.qcow2
      into 2024-12-17-barcas-lab/barcas-lab.qcow2.gz
 - Changing file ownership of dir. 2024-12-17-barcas-lab to gvisoc
Done with machine 'barcas-lab'
Processing machine 'rocky9':
 - Configuration dump for machine 'rocky9'
 - Compressing /var/lib/libvirt/images/rocky9.qcow2
      into 2024-12-17-rocky9/rocky9.qcow2.gz
 - Changing file ownership of dir. 2024-12-17-rocky9 to gvisoc
Done with machine 'rocky9'
Processing machine 'trisquel11':
 - Configuration dump for machine 'trisquel11'
 - Compressing /var/lib/libvirt/images/trisquel11.qcow2
      into 2024-12-17-trisquel11/trisquel11.qcow2.gz
 - Changing file ownership of dir. 2024-12-17-trisquel11 to gvisoc
Done with machine 'trisquel11'
Processing machine 'windows11':
 - Configuration dump for machine 'windows11'
 - Compressing /var/lib/libvirt/images/windows11.qcow2
      into 2024-12-17-windows11/windows11.qcow2.gz
 - Changing file ownership of dir. 2024-12-17-windows11 to gvisoc
Done with machine 'windows11'
Done for 2024-12-17

Limitations

In this particular iteration it will only export those VM that are inactive / shutdown.

Acknowledgements

Basedi on How to Backup a Virtual Machine on KVM? by PowerADM.com