Updates for libvirt image removal and use diretory
Summary by CodeRabbit
Release Notes
-
New Features
- Added support for migrating VMs between storage paths with automatic synchronization of VM data.
- Introduced secondary storage location for storing previous versions of VM configurations and metadata.
- Enhanced VM backup and restore capabilities during service transitions.
-
Documentation
- Updated help text to clarify VM storage supports both image files and directories.
- Added documentation for secondary VM storage configuration.
βοΈ Tip: You can customize this high-level summary in your review settings.
Walkthrough
This change implements a VM image file synchronization and backup system for the Unraid libvirt plugin. It adds UI controls to track IMAGE_FILE changes, syncs data between old and new image paths, collects VM metadata during shutdown, and prepares restoration of VM configurations on service restart.
Changes
| Cohort / File(s) | Summary |
|---|---|
UI & Configuration emhttp/plugins/dynamix.vm.manager/VMSettings.page, emhttp/plugins/dynamix.vm.manager/scripts/libvirtconfig, emhttp/languages/en_US/helptext.txt |
Added hidden OLD_IMAGE_FILE input to track prior image file path; updated default IMAGE_FILE to directory path; added help text for secondary volume/location storing VM backups; removed pattern restriction on IMAGE_FILE input. |
Image File Synchronization emhttp/plugins/dynamix.vm.manager/scripts/libvirt_init |
Added sync block comparing IMAGE_FILE and OLD_IMAGE_FILE; conditionally creates timestamped backups and uses rsync to migrate VM data based on whether old/new paths are .img files or directories. |
VM Backup & Restore Operations etc/rc.d/rc.libvirt, emhttp/plugins/dynamix.vm.manager/scripts/libvirtcopy, emhttp/plugins/dynamix.vm.manager/scripts/libvirtrestore, emhttp/plugins/dynamix.vm.manager/scripts/savehook.php |
Added pre-stop hook in rc.libvirt invoking libvirtcopy; new libvirtcopy script queries libvirt domains and writes VM metadata to JSON; new libvirtrestore prepares restoration paths; new savehook.php copies VM XML files to backup location on VM stop. |
Sequence Diagram(s)
sequenceDiagram
actor User
participant UI as VMSettings.page
participant libvirt_init as libvirt_init (script)
participant Config as domain.cfg
participant LibvirtSvc as Libvirt Service
participant libvirtcopy as libvirtcopy (script)
participant savehook as savehook.php
participant Storage as Storage Backend
User->>UI: Change IMAGE_FILE setting
UI->>Config: Save IMAGE_FILE + track OLD_IMAGE_FILE
activate libvirt_init
libvirt_init->>Config: Read IMAGE_FILE & OLD_IMAGE_FILE
alt Files differ and old path exists
libvirt_init->>Storage: Create timestamped backup of old image
libvirt_init->>Storage: Mount old image (if .img)
libvirt_init->>Storage: rsync contents to new location
libvirt_init->>Config: Update OLD_IMAGE_FILE to current path
else Files match or old path missing
libvirt_init->>Config: Log sync skipped
end
deactivate libvirt_init
User->>LibvirtSvc: Stop libvirt service
activate LibvirtSvc
libvirtcopy->>LibvirtSvc: Query all VM domains
libvirtcopy->>Config: Read VM storage metadata
libvirtcopy->>Storage: Write vms.json with VM locations
loop For each VM
savehook->>Config: Read vms.json
savehook->>Storage: Copy /etc/libvirt/qemu/{vm}.xml to backup path
end
LibvirtSvc->>LibvirtSvc: Stop services
deactivate LibvirtSvc
Estimated code review effort
π― 4 (Complex) | β±οΈ ~60 minutes
Poem
π° VM images shift and flow,
OLD and NEW paths dance below,
Sync the data, back it up,
When libvirt stops to fill its cup.
Safe migrations, configs savedβ
Your virtual machines are braved! π₯οΈ
π₯ Pre-merge checks | β 2 | β 1
β Failed checks (1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Title check | β Inconclusive | The title contains a typo ('diretory' instead of 'directory') and is somewhat vague, but it does relate to the main change: allowing libvirt to use directories instead of image files. | Correct the typo 'diretory' to 'directory' and consider a more specific title like 'Support libvirt directory storage and implement image migration logic' to better reflect the comprehensive nature of the changes. |
β Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | β Passed | Check skipped - CodeRabbitβs high-level summary is enabled. |
| Docstring Coverage | β Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
βοΈ Tip: You can configure your own custom pre-merge checks in the settings.
β¨ Finishing touches
- [ ] π Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
π§ PR Test Plugin Available
A test plugin has been generated for this PR that includes the modified files.
Version: 2026.01.07.1413
Build: View Workflow Run
π₯ Installation Instructions:
Install via Unraid Web UI:
- Go to Plugins β Install Plugin
- Copy and paste this URL:
https://preview.dl.unraid.net/pr-plugins/pr-1722/webgui-pr-1722.plg
- Click Install
Alternative: Direct Download
β οΈ Important Notes:
- Testing only: This plugin is for testing PR changes
- Backup included: Original files are automatically backed up
- Easy removal: Files are restored when plugin is removed
- Conflicts: Remove this plugin before installing production updates
π Modified Files:
Click to expand file list
emhttp/languages/en_US/helptext.txt
emhttp/plugins/dynamix.vm.manager/VMSettings.page
emhttp/plugins/dynamix.vm.manager/scripts/libvirt_init
emhttp/plugins/dynamix.vm.manager/scripts/libvirtconfig
emhttp/plugins/dynamix.vm.manager/scripts/libvirtcopy
emhttp/plugins/dynamix.vm.manager/scripts/libvirtrestore
emhttp/plugins/dynamix.vm.manager/scripts/savehook.php
π To Remove:
Navigate to Plugins β Installed Plugins and remove webgui-pr-1722, or run:
plugin remove webgui-pr-1722
π€ This comment is automatically generated and will be updated with each new push to this PR.