I have a virtual server running in qemu on proxmox. It has two physical disks attached to the host using a virtio: directive in 101.cfg as folllows
virtio2: /dev/disk/by-id/ata-vol1,backup=0 virtio3: /dev/disk/by-id/ata-vol2,backup=0
These contain a mirrored ZFS volume from which my files are served using nextcloud. This all works fine because these disks are never removed from the guest.
I also have a rotation of three other physical disks to which I back up (the physical controller is an LSI raid controller in JBOD configuration, the physical hardware is an HP Proiliant DL380e Gen8). I do this by zfs sending an updated snapshot from the storage array to whatever backup disk is present on the system. I had added these to the VM as follows:
virtio4: /dev/disk/by-id/ata-backup1-volname,backup=0 virtio5: /dev/disk/by-id/ata-backup2-volname,backup=0 virtio6: /dev/disk/by-id/ata-backup3-volname,backup=0
This sort of works but the problem is that none of those disks are hot swappable, so if I remove and insert disks in rotation, the guest stops being able to see them. I have disk hotplug enabled in my qemu config.
My question is what is the correct way to dynamically attach and detach these disks to my VM as they are inserted and removed?
I have been able to work out a partial solution using "qm monitor" to attach and detach the disk I am taking out by attaching and detaching virtio-scsi "pci cards" as follows:
qm> drive_add 0 file=/dev/disk/by-id/ata-<disk-id>,if=none,id=backup_vol,cache=none,detect-zeroes=on qm> device_add virtio-blk-pci,drive=backup_vol,id=backup_scsi_controller
qm> device_del backup_scsi_controller
(Source: https://blog.chrishowie.com/2019/09/19/hot-swapping-virtio-disks-on-qemu/ via Google cache)
I was thinking I could potentially add these to my backup scripts, but it doesn't seem to be possible however to run qm monitor commands from a shell script, and qm monitor will not take arguments or input from stdin. From reading aroud, it might be possible to create a socket into qemu-agent on the guest and inject this using JSON, but I know nothing about JSON and am really hoping there is an easier way.