From 4564cf757d1f49c46ab8ebe6e1c396904ff1432f Mon Sep 17 00:00:00 2001 From: Boris Budini Date: Tue, 11 Oct 2022 02:13:01 +0200 Subject: [PATCH] Support offline VMs with used PCI devices --- vzborg | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/vzborg b/vzborg index e911545..0085ac0 100755 --- a/vzborg +++ b/vzborg @@ -200,6 +200,8 @@ vzborg_backup() { vm_ext='vma' vm_hostname="$(grep -m 1 ^name ${vm_conf_dir}${VM_ID}.conf | awk '{print $2}')" vm_config="$(cat ${vm_conf_dir}${VM_ID}.conf)" + vm_status="$(qm status $VM_ID | sed 's/status: //g')" + mapfile -t vm_pci_config < <(grep "hostpci" ${vm_conf_dir}${VM_ID}.conf) else # unknown vm vm_type='--' @@ -210,6 +212,14 @@ vzborg_backup() { fi fi + #delete list of pci devices from stopped VMs + if [[ ($vm_status = "stopped" && $vm_type = "VM") ]]; then + for i in "${vm_pci_config[@]}"; do + sed -i "/$i/d" ${vm_conf_dir}${VM_ID}.conf + done + fi + + # Include vm type, id, hostname and configuration info as comment in backup backup_comment=$(echo -e "--comment=([vm_type]=${vm_type} [vm_id]=${VM_ID} [vm_hostname]=${vm_hostname})\nBEGIN_CONFIG>\n${vm_config}\n>${summary_file} + #add list of pci devices to stopped VMs + + if [[ ($vm_status = "stopped" && $vm_type = "VM") ]]; then + for i in "${vm_pci_config[@]}"; do + echo $i >> ${vm_conf_dir}${VM_ID}.conf + done + fi + done } vzborg_delete() {