1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 01:16:10 +00:00

feat(vmbackups): restore a backup over its own shut-off VM

The VM's disks are copied from the backup as new volumes beside the old
ones, which stay until removed by hand. Then the switch, recorded first and
finished by recovery: the NVRAM file and the TPM state are replaced by the
backup's, and the VM's own definition points at the copies with a new
generation ID. Its devices, MACs and UUID stay. A VM that is not shut off,
has snapshots or a saved state, or whose disks, UEFI firmware or TPM are
not the backup's, is refused; the checks run again before the switch.
This commit is contained in:
catborise 2026-11-17 15:59:22 +03:00
parent da52a23ed8
commit 5010e3a51c
8 changed files with 818 additions and 152 deletions

Binary file not shown.

View file

@ -11,7 +11,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-17 10:55+0000\n"
"POT-Creation-Date: 2026-11-17 12:59+0000\n"
"PO-Revision-Date: 2020-11-04 12:00+0000\n"
"Last-Translator: catborise <muhammetalisag@gmail.com>, 2020\n"
"Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n"
@ -3270,7 +3270,7 @@ msgstr ""
msgid "The name of the virtual machine must not contain any special characters"
msgstr "Sanal makine adı özel karakterler içeremez"
#: instances/jobs.py:73 vmbackups/jobs.py:84
#: instances/jobs.py:73 vmbackups/jobs.py:85
msgid "The VM moved to another compute after the job was queued"
msgstr "İş kuyruğa alındıktan sonra sanal makine başka bir sunucuya taşındı"
@ -3291,17 +3291,17 @@ msgstr "Klonun adını boş adlar listesinden seçin"
msgid "%(quota)s: cannot create '%(clone_name)s'."
msgstr "%(quota)s: '%(clone_name)s' oluşturulamıyor."
#: instances/jobs.py:206 instances/jobs.py:646 vmbackups/jobs.py:548
#: instances/jobs.py:206 instances/jobs.py:646 vmbackups/jobs.py:549
#, python-format
msgid "Instance '%(clone_name)s' already exists!"
msgstr "'%(clone_name)s' sanal makinesi zaten mevcut!"
#: instances/jobs.py:208 vmbackups/jobs.py:550
#: instances/jobs.py:208 vmbackups/jobs.py:551
#, python-format
msgid "Instance name '%(clone_name)s' is longer than 64 characters"
msgstr "'%(clone_name)s' sanal makine adı 64 karakterden uzun"
#: instances/jobs.py:211 vmbackups/jobs.py:552
#: instances/jobs.py:211 vmbackups/jobs.py:553
#, python-format
msgid "Instance name '%(clone_name)s' contains invalid characters!"
msgstr "Sanal makine adı '%(clone_name)s' geçersiz karakterler içermektedir!"
@ -3458,11 +3458,11 @@ msgid "Clone VM"
msgstr "Sanal makineyi klonla"
#: instances/jobs.py:656 instances/jobs.py:663 instances/jobs.py:1005
#: vmbackups/jobs.py:243 vmbackups/jobs.py:657
#: vmbackups/jobs.py:244 vmbackups/jobs.py:665 vmbackups/jobs.py:829
msgid "Copying disks"
msgstr "Diskler kopyalanıyor"
#: instances/jobs.py:715 vmbackups/jobs.py:319
#: instances/jobs.py:715 vmbackups/jobs.py:320
msgid "libvirt has no result of the copy"
msgstr "libvirt'te kopyanın sonucu yok"
@ -3475,7 +3475,7 @@ msgstr ""
"Kopyalama başarısız oldu: %(error)s. Konuğun dosya sistemleri çözülemedi "
"(%(thaw)s); şununla çözün: virsh domfsthaw %(vm)s"
#: instances/jobs.py:729 instances/jobs.py:821 vmbackups/jobs.py:325
#: instances/jobs.py:729 instances/jobs.py:821 vmbackups/jobs.py:326
msgid "The copy failed"
msgstr "Kopyalama başarısız oldu"
@ -3497,11 +3497,11 @@ msgstr ""
"Klonun bir birimi oluşturuluyordu; şu birimleri kontrol edin, sonra bu işi "
"çözün: %(volumes)s"
#: instances/jobs.py:801 vmbackups/jobs.py:362
#: instances/jobs.py:801 vmbackups/jobs.py:363
msgid "The job stopped before the copy started"
msgstr "İş, kopyalama başlamadan durdu"
#: instances/jobs.py:808 vmbackups/jobs.py:410
#: instances/jobs.py:808 vmbackups/jobs.py:411
msgid "libvirt is still copying the disks"
msgstr "libvirt diskleri hâlâ kopyalıyor"
@ -3542,12 +3542,12 @@ msgstr ""
msgid "Each network card needs a network"
msgstr "Her ağ kartının bir ağı olmalı"
#: instances/jobs.py:868 vrtManager/backup.py:283 vrtManager/instance.py:2871
#: instances/jobs.py:868 vrtManager/backup.py:300 vrtManager/instance.py:2871
#, python-format
msgid "This host has no network %(name)s"
msgstr "Bu sunucuda %(name)s ağı yok"
#: instances/jobs.py:870 vrtManager/backup.py:287 vrtManager/instance.py:2873
#: instances/jobs.py:870 vrtManager/backup.py:304 vrtManager/instance.py:2873
#, python-format
msgid "This host has no network filter %(name)s"
msgstr "Bu sunucuda %(name)s ağ filtresi yok"
@ -9795,7 +9795,7 @@ msgstr "Etkin"
msgid "Choose a compute or VMs, not both"
msgstr "Bir sunucu ya da sanal makineler seçin, ikisini birden değil"
#: vmbackups/forms.py:80 vmbackups/jobs.py:57
#: vmbackups/forms.py:80 vmbackups/jobs.py:58
#, python-format
msgid "Backup target %(target)s has no storage pool on %(compute)s"
msgstr "%(target)s yedek hedefinin %(compute)s üzerinde depolama havuzu yok"
@ -9804,12 +9804,12 @@ msgstr "%(target)s yedek hedefinin %(compute)s üzerinde depolama havuzu yok"
msgid "Keep one backup at least"
msgstr "En az bir yedek tutun"
#: vmbackups/jobs.py:67
#: vmbackups/jobs.py:68
msgid "The VM must be running, paused or shut off to be backed up"
msgstr ""
"Yedeklenmek için sanal makine çalışıyor, duraklatılmış ya da kapalı olmalı"
#: vmbackups/jobs.py:71
#: vmbackups/jobs.py:72
msgid ""
"A running VM's backup needs libvirt 11.10 or later; shut the VM down to back "
"it up"
@ -9817,45 +9817,45 @@ msgstr ""
"Çalışan bir sanal makinenin yedeği libvirt 11.10 veya sonrasını gerektirir; "
"yedeklemek için sanal makineyi kapatın"
#: vmbackups/jobs.py:73
#: vmbackups/jobs.py:74
msgid "A paused VM's file systems cannot be frozen"
msgstr "Duraklatılmış bir sanal makinenin dosya sistemleri dondurulamaz"
#: vmbackups/jobs.py:75
#: vmbackups/jobs.py:76
msgid "The guest agent does not answer: the file systems cannot be frozen"
msgstr "Konuk ajanı yanıt vermiyor: dosya sistemleri dondurulamaz"
#: vmbackups/jobs.py:125
#: vmbackups/jobs.py:126
msgid ""
"The VM's NVRAM file changed while it was backed up; back the VM up again"
msgstr ""
"Sanal makinenin NVRAM dosyası yedeklenirken değişti; sanal makineyi yeniden "
"yedekleyin"
#: vmbackups/jobs.py:195
#: vmbackups/jobs.py:196
msgid "Back up VM"
msgstr "Sanal makineyi yedekle"
#: vmbackups/jobs.py:230
#: vmbackups/jobs.py:231
msgid "The schedule's window ended before the backup could start"
msgstr "Yedek başlayamadan zamanlamanın penceresi bitti"
#: vmbackups/jobs.py:232
#: vmbackups/jobs.py:233
#, python-format
msgid ""
"%(compute)s went into maintenance before the scheduled backup could start"
msgstr "Zamanlanmış yedek başlayamadan %(compute)s bakıma alındı"
#: vmbackups/jobs.py:259 vmbackups/jobs.py:326
#: vmbackups/jobs.py:260 vmbackups/jobs.py:327
msgid "Writing the backup's files"
msgstr "Yedeğin dosyaları yazılıyor"
#: vmbackups/jobs.py:338
#: vmbackups/jobs.py:339
msgid "The guest's file systems could not be thawed; trying again"
msgstr ""
"Konuğun dosya sistemlerinin dondurulması kaldırılamadı; yeniden deneniyor"
#: vmbackups/jobs.py:387
#: vmbackups/jobs.py:388
#, python-format
msgid ""
"The VM is no longer on the compute the job ran on; check these volumes of the"
@ -9864,7 +9864,7 @@ msgstr ""
"Sanal makine artık işin çalıştığı sunucuda değil; yedek hedefindeki şu "
"birimleri kontrol edin, sonra bu işi çözün: %(volumes)s"
#: vmbackups/jobs.py:404
#: vmbackups/jobs.py:405
#, python-format
msgid ""
"A disk was being copied when the job stopped; check these volumes of the "
@ -9873,7 +9873,7 @@ msgstr ""
"İş durduğunda bir disk kopyalanıyordu; yedek hedefindeki şu birimleri kontrol"
" edin, sonra bu işi çözün: %(volumes)s"
#: vmbackups/jobs.py:414
#: vmbackups/jobs.py:415
#, python-format
msgid ""
"Another backup runs on the VM; check these volumes of the backup target, then"
@ -9882,7 +9882,7 @@ msgstr ""
"Sanal makinede başka bir yedekleme çalışıyor; yedek hedefindeki şu birimleri "
"kontrol edin, sonra bu işi çözün: %(volumes)s"
#: vmbackups/jobs.py:420
#: vmbackups/jobs.py:421
#, python-format
msgid ""
"libvirt has no result of the copy; check these volumes of the backup target, "
@ -9891,77 +9891,77 @@ msgstr ""
"libvirt'te kopyanın sonucu yok; yedek hedefindeki şu birimleri kontrol edin, "
"sonra bu işi çözün: %(volumes)s"
#: vmbackups/jobs.py:428
#: vmbackups/jobs.py:429
msgid "The job stopped before the copy ended"
msgstr "İş, kopyalama bitmeden durdu"
#: vmbackups/jobs.py:435
#: vmbackups/jobs.py:436
#, python-format
msgid "The backup's files could not be written: %(error)s"
msgstr "Yedeğin dosyaları yazılamadı: %(error)s"
#: vmbackups/jobs.py:455
#: vmbackups/jobs.py:456
#, python-format
msgid "No compute of backup target %(target)s reaches its storage pool"
msgstr ""
"%(target)s yedek hedefinin hiçbir sunucusu depolama havuzuna erişemiyor"
#: vmbackups/jobs.py:489
#: vmbackups/jobs.py:490
msgid "Delete backup"
msgstr "Yedeği sil"
#: vmbackups/jobs.py:500
#: vmbackups/jobs.py:501
msgid "This backup is being made; cancel its job to stop it"
msgstr "Bu yedek alınıyor; durdurmak için işini iptal edin"
#: vmbackups/jobs.py:513
#: vmbackups/jobs.py:514
msgid "The backup is no longer beyond what its schedule keeps; it is kept"
msgstr "Yedek artık zamanlamasının tuttuğu sayının dışında değil; tutuluyor"
#: vmbackups/jobs.py:565
#: vmbackups/jobs.py:566
#, python-format
msgid "The backup's file %(name)s is missing from the target"
msgstr "Yedeğin %(name)s dosyası hedefte yok"
#: vmbackups/jobs.py:568 vmbackups/jobs.py:570
#: vmbackups/jobs.py:569 vmbackups/jobs.py:571
#, python-format
msgid "The backup's file %(name)s differs from the one written"
msgstr "Yedeğin %(name)s dosyası yazılandan farklı"
#: vmbackups/jobs.py:581 vmbackups/templates/vmbackups/restore.html:7
msgid "Restore backup"
msgstr "Yedeği geri yükle"
#: vmbackups/jobs.py:594
msgid "Only a ready backup is restored"
msgstr "Yalnızca hazır bir yedek geri yüklenir"
#: vmbackups/jobs.py:624
#, python-format
msgid "A VM named %(name)s exists on %(compute)s"
msgstr "%(compute)s üzerinde %(name)s adlı bir sanal makine var"
#: vmbackups/jobs.py:632
#, python-format
msgid "This host has no active directory storage pool %(pool)s"
msgstr "Bu sunucuda %(pool)s adlı etkin bir dizin depolama havuzu yok"
#: vmbackups/jobs.py:648
#: vmbackups/jobs.py:580
#, python-format
msgid "The backup's TPM state file %(name)s is not a plain file name"
msgstr "Yedeğin TPM durum dosyası %(name)s düz bir dosya adı değil"
#: vmbackups/jobs.py:653
#: vmbackups/jobs.py:592 vmbackups/templates/vmbackups/restore.html:7
msgid "Restore backup"
msgstr "Yedeği geri yükle"
#: vmbackups/jobs.py:605 vmbackups/jobs.py:788
msgid "Only a ready backup is restored"
msgstr "Yalnızca hazır bir yedek geri yüklenir"
#: vmbackups/jobs.py:635
#, python-format
msgid "A VM named %(name)s exists on %(compute)s"
msgstr "%(compute)s üzerinde %(name)s adlı bir sanal makine var"
#: vmbackups/jobs.py:643 vmbackups/jobs.py:823
#, python-format
msgid "This host has no active directory storage pool %(pool)s"
msgstr "Bu sunucuda %(pool)s adlı etkin bir dizin depolama havuzu yok"
#: vmbackups/jobs.py:661
#, python-format
msgid "The NVRAM file %(path)s exists already"
msgstr "%(path)s NVRAM dosyası zaten var"
#: vmbackups/jobs.py:689
#: vmbackups/jobs.py:697
#, python-format
msgid "The VM was restored; it did not start: %(error)s"
msgstr "Sanal makine geri yüklendi; başlamadı: %(error)s"
#: vmbackups/jobs.py:711
#: vmbackups/jobs.py:719 vmbackups/jobs.py:898
#, python-format
msgid ""
"A disk was being copied when the job stopped; check this volume, then resolve"
@ -9970,7 +9970,7 @@ msgstr ""
"İş durduğunda bir disk kopyalanıyordu; bu birimi kontrol edin, sonra bu işi "
"çözün: %(volumes)s"
#: vmbackups/jobs.py:716
#: vmbackups/jobs.py:724 vmbackups/jobs.py:904
#, python-format
msgid ""
"Storage pool %(pool)s is not active; the restore's copies in it are removed "
@ -9979,15 +9979,83 @@ msgstr ""
"%(pool)s depolama havuzu etkin değil; geri yüklemenin içindeki kopyaları "
"havuz etkin olunca kaldırılır"
#: vmbackups/jobs.py:730
#: vmbackups/jobs.py:738
msgid "The VM was not defined; its copies were removed"
msgstr "Sanal makine tanımlanmadı; kopyaları kaldırıldı"
#: vmbackups/jobs.py:749 vmbackups/templates/vmbackups/target.html:18
#: vmbackups/jobs.py:750
msgid "Shut the VM down to restore a backup over it"
msgstr "Üzerine yedek geri yüklemek için VM'i kapatın"
#: vmbackups/jobs.py:753
msgid "The VM has snapshots; delete them to restore a backup over it"
msgstr ""
"VM'in anlık görüntüleri var; üzerine yedek geri yüklemek için onları silin"
#: vmbackups/jobs.py:758
#, python-format
msgid ""
"The VM's disks (%(now)s) are not the backup's (%(then)s); restore it as a new"
" VM or one disk"
msgstr ""
"VM'in diskleri (%(now)s) yedeğinkiler (%(then)s) değil; yeni bir VM olarak ya"
" da tek disk olarak geri yükleyin"
#: vmbackups/jobs.py:761
msgid "The VM's UEFI firmware changed since the backup; restore it as a new VM"
msgstr ""
"VM'in UEFI donanım yazılımı yedekten sonra değişti; yeni bir VM olarak geri "
"yükleyin"
#: vmbackups/jobs.py:763
msgid "The VM's TPM changed since the backup; restore it as a new VM"
msgstr "VM'in TPM'i yedekten sonra değişti; yeni bir VM olarak geri yükleyin"
#: vmbackups/jobs.py:778
msgid "Restore backup over the VM"
msgstr "Yedeği VM'in üzerine geri yükle"
#: vmbackups/jobs.py:791
msgid "The backup's VM is no longer in the panel; restore it as a new VM"
msgstr "Yedeğin VM'i artık panelde yok; yeni bir VM olarak geri yükleyin"
#: vmbackups/jobs.py:814
msgid "The VM's disks changed after the job was queued"
msgstr "İş kuyruğa alındıktan sonra VM'in diskleri değişti"
#: vmbackups/jobs.py:842
msgid "The VM changed while its backup was copied; it keeps its disks"
msgstr "Yedeği kopyalanırken VM değişti; VM disklerini koruyor"
#: vmbackups/jobs.py:843
msgid "Replacing the VM's disks"
msgstr "VM'in diskleri değiştiriliyor"
#: vmbackups/jobs.py:881
msgid ""
"The VM moved to another compute; check its disks and the restore's copies, "
"then resolve this job"
msgstr ""
"VM başka bir sunucuya taşındı; disklerini ve geri yüklemenin kopyalarını "
"denetleyin, sonra bu işi çözümleyin"
#: vmbackups/jobs.py:891
msgid ""
"The VM was started while its disks were being replaced; check its disks, then"
" resolve this job"
msgstr ""
"VM'in diskleri değiştirilirken VM başlatıldı; disklerini denetleyin, sonra bu"
" işi çözümleyin"
#: vmbackups/jobs.py:909
msgid "The VM keeps its disks; the restore's copies were removed"
msgstr "VM disklerini koruyor; geri yüklemenin kopyaları silindi"
#: vmbackups/jobs.py:928 vmbackups/templates/vmbackups/target.html:18
msgid "Read backups from target"
msgstr "Yedekleri hedeften oku"
#: vmbackups/jobs.py:797
#: vmbackups/jobs.py:976
#, python-format
msgid ""
"Not read, as a file of the backup is missing, changed or unreadable: "
@ -9996,11 +10064,11 @@ msgstr ""
"Yedeğin bir dosyası eksik, değişmiş ya da okunamaz olduğu için okunmadı: "
"%(names)s"
#: vmbackups/jobs.py:813
#: vmbackups/jobs.py:992
msgid "Check backup target"
msgstr "Yedek hedefini denetle"
#: vmbackups/jobs.py:840
#: vmbackups/jobs.py:1019
#, python-format
msgid "Files of these backups are missing from the target: %(backups)s"
msgstr "Şu yedeklerin dosyaları hedefte yok: %(backups)s"
@ -10462,7 +10530,7 @@ msgid ""
"written"
msgstr "Yedek hedefinden geri okunan %(name)s dosyası yazılandan farklı"
#: vrtManager/backup.py:270
#: vrtManager/backup.py:287
#, python-format
msgid ""
"This host cannot run the VM's emulator %(emulator)s with machine type "
@ -10471,17 +10539,17 @@ msgstr ""
"Bu sunucu sanal makinenin %(emulator)s öykünücüsünü %(machine)s makine "
"türüyle çalıştıramıyor: %(error)s"
#: vrtManager/backup.py:274
#: vrtManager/backup.py:291
#, python-format
msgid "This host has no firmware %(loader)s"
msgstr "Bu sunucuda %(loader)s firmware'i yok"
#: vrtManager/backup.py:280
#: vrtManager/backup.py:297
#, python-format
msgid "This host offers no TPM 2.0 %(model)s: install swtpm on it"
msgstr "Bu ana makine TPM 2.0 %(model)s sunmuyor: üzerine swtpm kurun"
#: vrtManager/backup.py:285
#: vrtManager/backup.py:302
#, python-format
msgid "This host has no bridge %(name)s"
msgstr "Bu sunucuda %(name)s köprüsü yok"

Binary file not shown.

View file

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-17 10:55+0000\n"
"POT-Creation-Date: 2026-11-17 12:59+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
@ -3115,7 +3115,7 @@ msgstr "控制台监听的不只是 localhost;只有管理员可以移除其
msgid "The name of the virtual machine must not contain any special characters"
msgstr "虚拟机名称不能包含任何特殊字符"
#: instances/jobs.py:73 vmbackups/jobs.py:84
#: instances/jobs.py:73 vmbackups/jobs.py:85
msgid "The VM moved to another compute after the job was queued"
msgstr "任务排队后,虚拟机已移到另一个计算节点"
@ -3136,17 +3136,17 @@ msgstr "请从可用名称列表中选择克隆的名称"
msgid "%(quota)s: cannot create '%(clone_name)s'."
msgstr "%(quota)s:无法创建“%(clone_name)s”。"
#: instances/jobs.py:206 instances/jobs.py:646 vmbackups/jobs.py:548
#: instances/jobs.py:206 instances/jobs.py:646 vmbackups/jobs.py:549
#, python-format
msgid "Instance '%(clone_name)s' already exists!"
msgstr "虚拟机 '%(clone_name)s' 已存在!"
#: instances/jobs.py:208 vmbackups/jobs.py:550
#: instances/jobs.py:208 vmbackups/jobs.py:551
#, python-format
msgid "Instance name '%(clone_name)s' is longer than 64 characters"
msgstr "虚拟机名称“%(clone_name)s”超过 64 个字符"
#: instances/jobs.py:211 vmbackups/jobs.py:552
#: instances/jobs.py:211 vmbackups/jobs.py:553
#, python-format
msgid "Instance name '%(clone_name)s' contains invalid characters!"
msgstr "虚拟机名称 '%(clone_name)s' 包含无效字符!"
@ -3288,11 +3288,11 @@ msgid "Clone VM"
msgstr "克隆虚拟机"
#: instances/jobs.py:656 instances/jobs.py:663 instances/jobs.py:1005
#: vmbackups/jobs.py:243 vmbackups/jobs.py:657
#: vmbackups/jobs.py:244 vmbackups/jobs.py:665 vmbackups/jobs.py:829
msgid "Copying disks"
msgstr "正在复制磁盘"
#: instances/jobs.py:715 vmbackups/jobs.py:319
#: instances/jobs.py:715 vmbackups/jobs.py:320
msgid "libvirt has no result of the copy"
msgstr "libvirt 没有复制的结果"
@ -3303,7 +3303,7 @@ msgid ""
"(%(thaw)s); thaw them with: virsh domfsthaw %(vm)s"
msgstr "复制失败:%(error)s。无法解冻客户机的文件系统(%(thaw)s);请用以下命令解冻:virsh domfsthaw %(vm)s"
#: instances/jobs.py:729 instances/jobs.py:821 vmbackups/jobs.py:325
#: instances/jobs.py:729 instances/jobs.py:821 vmbackups/jobs.py:326
msgid "The copy failed"
msgstr "复制失败"
@ -3321,11 +3321,11 @@ msgid ""
"this job: %(volumes)s"
msgstr "克隆的一个卷正在创建中;请检查这些卷,然后处理此任务:%(volumes)s"
#: instances/jobs.py:801 vmbackups/jobs.py:362
#: instances/jobs.py:801 vmbackups/jobs.py:363
msgid "The job stopped before the copy started"
msgstr "任务在复制开始前停止"
#: instances/jobs.py:808 vmbackups/jobs.py:410
#: instances/jobs.py:808 vmbackups/jobs.py:411
msgid "libvirt is still copying the disks"
msgstr "libvirt 仍在复制磁盘"
@ -3358,12 +3358,12 @@ msgstr "镜像已存在。请检查卷或更改虚拟机名称"
msgid "Each network card needs a network"
msgstr "每个网卡都需要一个网络"
#: instances/jobs.py:868 vrtManager/backup.py:283 vrtManager/instance.py:2871
#: instances/jobs.py:868 vrtManager/backup.py:300 vrtManager/instance.py:2871
#, python-format
msgid "This host has no network %(name)s"
msgstr "此主机没有网络 %(name)s"
#: instances/jobs.py:870 vrtManager/backup.py:287 vrtManager/instance.py:2873
#: instances/jobs.py:870 vrtManager/backup.py:304 vrtManager/instance.py:2873
#, python-format
msgid "This host has no network filter %(name)s"
msgstr "此主机没有网络过滤器 %(name)s"
@ -9238,7 +9238,7 @@ msgstr "已启用"
msgid "Choose a compute or VMs, not both"
msgstr "请选择一个计算节点或若干虚拟机,不能同时选择"
#: vmbackups/forms.py:80 vmbackups/jobs.py:57
#: vmbackups/forms.py:80 vmbackups/jobs.py:58
#, python-format
msgid "Backup target %(target)s has no storage pool on %(compute)s"
msgstr "备份目标 %(target)s 在 %(compute)s 上没有存储池"
@ -9247,182 +9247,241 @@ msgstr "备份目标 %(target)s 在 %(compute)s 上没有存储池"
msgid "Keep one backup at least"
msgstr "至少保留一个备份"
#: vmbackups/jobs.py:67
#: vmbackups/jobs.py:68
msgid "The VM must be running, paused or shut off to be backed up"
msgstr "虚拟机必须处于运行、暂停或关闭状态才能备份"
#: vmbackups/jobs.py:71
#: vmbackups/jobs.py:72
msgid ""
"A running VM's backup needs libvirt 11.10 or later; shut the VM down to back "
"it up"
msgstr "运行中虚拟机的备份需要 libvirt 11.10 或更高版本;请关闭虚拟机后再备份"
#: vmbackups/jobs.py:73
#: vmbackups/jobs.py:74
msgid "A paused VM's file systems cannot be frozen"
msgstr "无法冻结已暂停虚拟机的文件系统"
#: vmbackups/jobs.py:75
#: vmbackups/jobs.py:76
msgid "The guest agent does not answer: the file systems cannot be frozen"
msgstr "客户机代理没有响应:无法冻结文件系统"
#: vmbackups/jobs.py:125
#: vmbackups/jobs.py:126
msgid ""
"The VM's NVRAM file changed while it was backed up; back the VM up again"
msgstr "虚拟机的 NVRAM 文件在备份期间发生了变化;请重新备份该虚拟机"
#: vmbackups/jobs.py:195
#: vmbackups/jobs.py:196
msgid "Back up VM"
msgstr "备份虚拟机"
#: vmbackups/jobs.py:230
#: vmbackups/jobs.py:231
msgid "The schedule's window ended before the backup could start"
msgstr "备份开始前计划的时间窗口已结束"
#: vmbackups/jobs.py:232
#: vmbackups/jobs.py:233
#, python-format
msgid ""
"%(compute)s went into maintenance before the scheduled backup could start"
msgstr "计划的备份开始前 %(compute)s 已进入维护"
#: vmbackups/jobs.py:259 vmbackups/jobs.py:326
#: vmbackups/jobs.py:260 vmbackups/jobs.py:327
msgid "Writing the backup's files"
msgstr "正在写入备份文件"
#: vmbackups/jobs.py:338
#: vmbackups/jobs.py:339
msgid "The guest's file systems could not be thawed; trying again"
msgstr "无法解冻客户机的文件系统;正在重试"
#: vmbackups/jobs.py:387
#: vmbackups/jobs.py:388
#, python-format
msgid ""
"The VM is no longer on the compute the job ran on; check these volumes of the"
" backup target, then resolve this job: %(volumes)s"
msgstr "虚拟机已不在作业运行的计算节点上;请检查备份目标中的这些卷,然后解决此作业:%(volumes)s"
#: vmbackups/jobs.py:404
#: vmbackups/jobs.py:405
#, python-format
msgid ""
"A disk was being copied when the job stopped; check these volumes of the "
"backup target, then resolve this job: %(volumes)s"
msgstr "作业停止时正在复制磁盘;请检查备份目标中的这些卷,然后解决此作业:%(volumes)s"
#: vmbackups/jobs.py:414
#: vmbackups/jobs.py:415
#, python-format
msgid ""
"Another backup runs on the VM; check these volumes of the backup target, then"
" resolve this job: %(volumes)s"
msgstr "虚拟机上正在运行另一个备份;请检查备份目标中的这些卷,然后解决此作业:%(volumes)s"
#: vmbackups/jobs.py:420
#: vmbackups/jobs.py:421
#, python-format
msgid ""
"libvirt has no result of the copy; check these volumes of the backup target, "
"then resolve this job: %(volumes)s"
msgstr "libvirt 没有复制的结果;请检查备份目标中的这些卷,然后解决此作业:%(volumes)s"
#: vmbackups/jobs.py:428
#: vmbackups/jobs.py:429
msgid "The job stopped before the copy ended"
msgstr "作业在复制结束前停止"
#: vmbackups/jobs.py:435
#: vmbackups/jobs.py:436
#, python-format
msgid "The backup's files could not be written: %(error)s"
msgstr "无法写入备份文件:%(error)s"
#: vmbackups/jobs.py:455
#: vmbackups/jobs.py:456
#, python-format
msgid "No compute of backup target %(target)s reaches its storage pool"
msgstr "备份目标 %(target)s 的计算节点都无法访问其存储池"
#: vmbackups/jobs.py:489
#: vmbackups/jobs.py:490
msgid "Delete backup"
msgstr "删除备份"
#: vmbackups/jobs.py:500
#: vmbackups/jobs.py:501
msgid "This backup is being made; cancel its job to stop it"
msgstr "此备份正在创建;要停止它,请取消其作业"
#: vmbackups/jobs.py:513
#: vmbackups/jobs.py:514
msgid "The backup is no longer beyond what its schedule keeps; it is kept"
msgstr "该备份已不再超出其计划保留的数量;予以保留"
#: vmbackups/jobs.py:565
#: vmbackups/jobs.py:566
#, python-format
msgid "The backup's file %(name)s is missing from the target"
msgstr "目标中缺少备份文件 %(name)s"
#: vmbackups/jobs.py:568 vmbackups/jobs.py:570
#: vmbackups/jobs.py:569 vmbackups/jobs.py:571
#, python-format
msgid "The backup's file %(name)s differs from the one written"
msgstr "备份文件 %(name)s 与写入的不同"
#: vmbackups/jobs.py:581 vmbackups/templates/vmbackups/restore.html:7
msgid "Restore backup"
msgstr "恢复备份"
#: vmbackups/jobs.py:594
msgid "Only a ready backup is restored"
msgstr "只能恢复就绪的备份"
#: vmbackups/jobs.py:624
#, python-format
msgid "A VM named %(name)s exists on %(compute)s"
msgstr "%(compute)s 上已存在名为 %(name)s 的虚拟机"
#: vmbackups/jobs.py:632
#, python-format
msgid "This host has no active directory storage pool %(pool)s"
msgstr "此主机没有名为 %(pool)s 的活动目录存储池"
#: vmbackups/jobs.py:648
#: vmbackups/jobs.py:580
#, python-format
msgid "The backup's TPM state file %(name)s is not a plain file name"
msgstr "备份的 TPM 状态文件 %(name)s 不是普通文件名"
#: vmbackups/jobs.py:653
#: vmbackups/jobs.py:592 vmbackups/templates/vmbackups/restore.html:7
msgid "Restore backup"
msgstr "恢复备份"
#: vmbackups/jobs.py:605 vmbackups/jobs.py:788
msgid "Only a ready backup is restored"
msgstr "只能恢复就绪的备份"
#: vmbackups/jobs.py:635
#, python-format
msgid "A VM named %(name)s exists on %(compute)s"
msgstr "%(compute)s 上已存在名为 %(name)s 的虚拟机"
#: vmbackups/jobs.py:643 vmbackups/jobs.py:823
#, python-format
msgid "This host has no active directory storage pool %(pool)s"
msgstr "此主机没有名为 %(pool)s 的活动目录存储池"
#: vmbackups/jobs.py:661
#, python-format
msgid "The NVRAM file %(path)s exists already"
msgstr "NVRAM 文件 %(path)s 已存在"
#: vmbackups/jobs.py:689
#: vmbackups/jobs.py:697
#, python-format
msgid "The VM was restored; it did not start: %(error)s"
msgstr "虚拟机已恢复;但未能启动:%(error)s"
#: vmbackups/jobs.py:711
#: vmbackups/jobs.py:719 vmbackups/jobs.py:898
#, python-format
msgid ""
"A disk was being copied when the job stopped; check this volume, then resolve"
" this job: %(volumes)s"
msgstr "作业停止时正在复制磁盘;请检查此卷,然后解决此作业:%(volumes)s"
#: vmbackups/jobs.py:716
#: vmbackups/jobs.py:724 vmbackups/jobs.py:904
#, python-format
msgid ""
"Storage pool %(pool)s is not active; the restore's copies in it are removed "
"when it is"
msgstr "存储池 %(pool)s 未激活;其中恢复的副本将在其激活后删除"
#: vmbackups/jobs.py:730
#: vmbackups/jobs.py:738
msgid "The VM was not defined; its copies were removed"
msgstr "虚拟机未定义;其副本已删除"
#: vmbackups/jobs.py:749 vmbackups/templates/vmbackups/target.html:18
#: vmbackups/jobs.py:750
msgid "Shut the VM down to restore a backup over it"
msgstr "请先将虚拟机关机,再将备份恢复到其上"
#: vmbackups/jobs.py:753
msgid "The VM has snapshots; delete them to restore a backup over it"
msgstr "虚拟机有快照;请删除它们后再将备份恢复到其上"
#: vmbackups/jobs.py:758
#, python-format
msgid ""
"The VM's disks (%(now)s) are not the backup's (%(then)s); restore it as a new"
" VM or one disk"
msgstr "虚拟机的磁盘(%(now)s)与备份的(%(then)s)不同;请恢复为新虚拟机或恢复单个磁盘"
#: vmbackups/jobs.py:761
msgid "The VM's UEFI firmware changed since the backup; restore it as a new VM"
msgstr "备份之后虚拟机的 UEFI 固件已更改;请恢复为新虚拟机"
#: vmbackups/jobs.py:763
msgid "The VM's TPM changed since the backup; restore it as a new VM"
msgstr "备份之后虚拟机的 TPM 已更改;请恢复为新虚拟机"
#: vmbackups/jobs.py:778
msgid "Restore backup over the VM"
msgstr "将备份恢复到虚拟机上"
#: vmbackups/jobs.py:791
msgid "The backup's VM is no longer in the panel; restore it as a new VM"
msgstr "备份的虚拟机已不在面板中;请恢复为新虚拟机"
#: vmbackups/jobs.py:814
msgid "The VM's disks changed after the job was queued"
msgstr "任务排队后虚拟机的磁盘已更改"
#: vmbackups/jobs.py:842
msgid "The VM changed while its backup was copied; it keeps its disks"
msgstr "复制备份期间虚拟机发生了变化;虚拟机保留其磁盘"
#: vmbackups/jobs.py:843
msgid "Replacing the VM's disks"
msgstr "正在替换虚拟机的磁盘"
#: vmbackups/jobs.py:881
msgid ""
"The VM moved to another compute; check its disks and the restore's copies, "
"then resolve this job"
msgstr "虚拟机已迁移到另一台计算节点;请检查其磁盘和恢复的副本,然后处理此任务"
#: vmbackups/jobs.py:891
msgid ""
"The VM was started while its disks were being replaced; check its disks, then"
" resolve this job"
msgstr "替换磁盘期间虚拟机被启动;请检查其磁盘,然后处理此任务"
#: vmbackups/jobs.py:909
msgid "The VM keeps its disks; the restore's copies were removed"
msgstr "虚拟机保留其磁盘;恢复的副本已删除"
#: vmbackups/jobs.py:928 vmbackups/templates/vmbackups/target.html:18
msgid "Read backups from target"
msgstr "从目标读取备份"
#: vmbackups/jobs.py:797
#: vmbackups/jobs.py:976
#, python-format
msgid ""
"Not read, as a file of the backup is missing, changed or unreadable: "
"%(names)s"
msgstr "由于备份的某个文件缺失、已更改或无法读取,未读取:%(names)s"
#: vmbackups/jobs.py:813
#: vmbackups/jobs.py:992
msgid "Check backup target"
msgstr "检查备份目标"
#: vmbackups/jobs.py:840
#: vmbackups/jobs.py:1019
#, python-format
msgid "Files of these backups are missing from the target: %(backups)s"
msgstr "以下备份的文件在目标中缺失:%(backups)s"
@ -9845,24 +9904,24 @@ msgid ""
"written"
msgstr "从备份目标读回的文件 %(name)s 与写入的不同"
#: vrtManager/backup.py:270
#: vrtManager/backup.py:287
#, python-format
msgid ""
"This host cannot run the VM's emulator %(emulator)s with machine type "
"%(machine)s: %(error)s"
msgstr "此主机无法以机器类型 %(machine)s 运行虚拟机的模拟器 %(emulator)s:%(error)s"
#: vrtManager/backup.py:274
#: vrtManager/backup.py:291
#, python-format
msgid "This host has no firmware %(loader)s"
msgstr "此主机没有固件 %(loader)s"
#: vrtManager/backup.py:280
#: vrtManager/backup.py:297
#, python-format
msgid "This host offers no TPM 2.0 %(model)s: install swtpm on it"
msgstr "此主机不提供 TPM 2.0 %(model)s:请在其上安装 swtpm"
#: vrtManager/backup.py:285
#: vrtManager/backup.py:302
#, python-format
msgid "This host has no bridge %(name)s"
msgstr "此主机没有网桥 %(name)s"

View file

@ -18,7 +18,7 @@ from libvirt import VIR_DOMAIN_PAUSED, VIR_DOMAIN_RUNNING, VIR_DOMAIN_SHUTOFF, V
from appsettings.settings import app_settings
from computes.models import Compute
from instances.jobs import PAUSED_FROZEN, THAW_FAILED, _instance, _log, _snapshot_free_space, record_vm, vm_claims
from instances.jobs import MOVED, PAUSED_FROZEN, THAW_FAILED, _instance, _log, _snapshot_free_space, record_vm, vm_claims
from instances.utils import get_random_mac_address
from instances.models import Instance
from operations import claims
@ -27,9 +27,10 @@ from operations.models import Claim, Operation
from operations.utils import safe_text, say
from vrtManager import util
from vrtManager.backup import (backup_file_names, check_restore_host, check_target_space, get_file, manifest_names, put_file,
remove_files, restore_definition, target_pool, volume_exists, wvmBackup)
remove_files, restore_definition, restore_over_definition, target_pool, volume_exists,
wvmBackup)
from vrtManager.connection import NVRAM_DIR, wvmConnect
from vrtManager.instance import wvmInstance
from vrtManager.instance import PERSISTENT_XML, wvmInstance
from vrtManager.storage import wvmStorage
from vrtManager.instance import LIVE_CLONE_MIN_LIBVIRT
@ -570,6 +571,16 @@ def _check_files(conn, pool, files):
raise util.OperationError(_("The backup's file %(name)s differs from the one written"), name=f["volume"])
def _tpm_files(backup):
"""The backup's TPM state files; a manifest read from a target names
them: each is a file of the VM's state directory only."""
files = list(backup.files.filter(role=BackupFile.TPM).order_by("dev"))
for f in files:
if not f.dev or "/" in f.dev or f.dev.startswith("."):
raise util.OperationError(_("The backup's TPM state file %(name)s is not a plain file name"), name=f.dev)
return files
@register
class RestoreBackup(Kind):
"""A ready backup made a new VM on a compute that has the target's pool:
@ -642,10 +653,7 @@ class RestoreBackup(Kind):
# the VM's own file in libvirt's directory; libvirt makes it from the template when none was kept
nvram = os.path.join(NVRAM_DIR, p["name"] + "_VARS" + os.path.splitext(old_nvram)[1]) if old_nvram else None
macs = [get_random_mac_address() for _nic in tree.findall("devices/interface")]
tpm_files = list(backup.files.filter(role=BackupFile.TPM).order_by("dev"))
for f in tpm_files: # a manifest read from a target names them: a file of the VM's directory only
if not f.dev or "/" in f.dev or f.dev.startswith("."):
raise util.OperationError(_("The backup's TPM state file %(name)s is not a plain file name"), name=f.dev)
tpm_files = _tpm_files(backup)
if nvram:
# a file of that name may be a removed VM's kept one, or another VM's: never taken, never removed
with conn._nvram_pool() as nvram_pool:
@ -733,6 +741,187 @@ class RestoreBackup(Kind):
return _log(op, state, f"restored from the backup of {op.intent['from']} taken {op.intent['time']}")
def _over_plan(backup, proxy):
"""What a restore over the backup's VM makes: {"disks": {dev: [pool,
volume name]}, "nvram": the VM's NVRAM path or None, "tpm": bool}.
Refuses a VM that is not shut off, has snapshots, or whose disks, UEFI
firmware or TPM are not the backup's."""
if proxy.get_status() != VIR_DOMAIN_SHUTOFF:
raise util.OperationError(_("Shut the VM down to restore a backup over it"))
if proxy.instance.snapshotNum(0):
# their metadata names the disks that are replaced
raise util.OperationError(_("The VM has snapshots; delete them to restore a backup over it"))
plan = proxy.backup_plan()
files = {f.dev: f for f in backup.files.filter(role=BackupFile.DISK)}
now = {d["dev"]: d for d in plan["disks"]}
if set(now) != set(files):
raise util.OperationError(_("The VM's disks (%(now)s) are not the backup's (%(then)s); restore it as a new VM "
"or one disk"), now=", ".join(sorted(now)), then=", ".join(sorted(files)))
if bool(plan["nvram"]) != (backup.manifest.get("nvram", "none") != "none"):
raise util.OperationError(_("The VM's UEFI firmware changed since the backup; restore it as a new VM"))
if plan["tpm"] != (backup.manifest.get("tpm", "none") != "none"):
raise util.OperationError(_("The VM's TPM changed since the backup; restore it as a new VM"))
time = timezone.localtime(backup.created_at).strftime("%Y%m%d-%H%M")
return {"disks": {dev: [now[dev]["pool"], f"{proxy.instance.name()}-{dev}-{time}.{'qcow2' if f.format == 'qcow2' else 'raw'}"]
for dev, f in files.items()},
"nvram": plan["nvram"], "tpm": plan["tpm"]}
@register
class RestoreOver(Kind):
"""A ready backup restored over its own shut-off VM: its disks copied as
new volumes beside the VM's (kept until removed by hand), then the
switch: the NVRAM file and TPM state replaced and the VM's definition
pointed at the copies. The rest of the definition stays the VM's."""
name = "backup.restore_over"
label = _("Restore backup over the VM")
progress_bytes = True
def normalize(self, raw):
return {"backup": str(UUID(str(raw["backup"])))}
def plan(self, user, params):
_superuser(user)
backup = _backup(params)
if backup.state != Backup.READY:
raise util.OperationError(_("Only a ready backup is restored"))
instance = backup.instance
if instance is None:
raise util.OperationError(_("The backup's VM is no longer in the panel; restore it as a new VM"))
_target_row(backup.target, instance.compute)
over = _over_plan(backup, _proxy(instance))
keys = {claims.compute_key(instance.compute_id): Claim.SHARED, claims.instance_key(instance.uuid): Claim.EXCLUSIVE,
claims.backup_key(backup.uuid): Claim.SHARED, claims.backup_target_key(backup.target_id): Claim.EXCLUSIVE}
for pool, name in over["disks"].values(): # no other job makes a volume of these names meanwhile
keys[claims.volume_key(instance.compute_id, pool, name)] = Claim.EXCLUSIVE
return Plan(
claims=keys,
resource=claims.instance_key(instance.uuid),
label=f"{instance.compute.name}/{instance.name}",
intent={"compute": instance.compute_id, "uuid": instance.uuid, "over": over,
"time": timezone.localtime(backup.created_at).strftime("%Y-%m-%d %H:%M")},
)
def run(self, op, ctx):
_superuser(op.user)
backup = _backup(op.params)
instance = _instance(backup.instance_id)
if instance.compute_id != op.intent["compute"]:
raise util.OperationError(MOVED)
proxy = _proxy(instance)
if _over_plan(backup, proxy) != op.intent["over"]:
raise util.OperationError(_("The VM's disks changed after the job was queued"))
row = _target_row(backup.target, instance.compute)
tpool = target_pool(proxy, row.pool, row.pool_uuid)
_check_files(proxy, tpool, backup.files.values("role", "volume", "capacity", "sha256"))
_tpm_files(backup)
disks = {f.dev: f for f in backup.files.filter(role=BackupFile.DISK)}
pools = proxy.file_pools()
for dev, (pool, name) in op.intent["over"]["disks"].items():
if pool not in pools:
raise util.OperationError(_("This host has no active directory storage pool %(pool)s"), pool=pool)
wvmInstance._refuse_taken(pools[pool][0], name)
for pool in {pool for pool, _name in op.intent["over"]["disks"].values()}:
check_target_space(pools[pool][0], [{"capacity": disks[dev].capacity} for dev, (p, _n) in
op.intent["over"]["disks"].items() if p == pool], **_free_space())
ctx.set_phase(_("Copying disks"))
c = instance.compute
paths = {}
for dev, (pool, name) in op.intent["over"]["disks"].items():
ctx.record_intent(copying=dev)
storage = wvmStorage(c.hostname, c.login, c.password, c.type, pool)
try:
paths[dev] = storage.clone_volume(tpool.storageVolLookupByName(disks[dev].volume), name,
vol_fmt=disks[dev].format, disk_owner_uid=_owner()[0],
disk_owner_gid=_owner()[1])
except libvirtError: # libvirt answered: its claimed name is removed with the copies
ctx.record_intent(copied=[*op.intent.get("copied", []), dev], copying=None)
raise
ctx.record_intent(copied=[*op.intent.get("copied", []), dev], paths=paths, copying=None)
# the VM may have been started or saved outside the panel meanwhile: then it keeps its disks
if _over_plan(backup, proxy) != op.intent["over"]:
raise util.OperationError(_("The VM changed while its backup was copied; it keeps its disks"))
ctx.set_phase(_("Replacing the VM's disks"))
ctx.record_intent(switching=True, autostart=bool(proxy.instance.autostart()))
return self._switch(op, backup, proxy, tpool)
@staticmethod
def _switch(op, backup, proxy, tpool):
"""The NVRAM file and TPM state replaced, the disks' sources set; runs
again in recovery until it is done."""
over = op.intent["over"]
# a host booting mid-switch starts nothing: the old disks with the backup's NVRAM and TPM would not match
proxy.instance.setAutostart(0)
if over["nvram"]:
nvram = backup.files.filter(role=BackupFile.NVRAM).first()
with proxy._nvram_pool() as nvram_pool:
remove_files(nvram_pool, [os.path.basename(over["nvram"])])
if nvram is not None: # else never written: libvirt makes it from the template
proxy.upload_volume(nvram_pool, os.path.basename(over["nvram"]), get_file(proxy, tpool, nvram.volume),
owner=_owner(), mode="0600")
if over["tpm"]:
files = _tpm_files(backup)
with proxy._tpm_pool(op.intent["uuid"], build=bool(files)) as tpm_pool:
if tpm_pool is not None: # swtpm's .lock stays
remove_files(tpm_pool, [n for n in tpm_pool.listVolumes() if not n.startswith(".")])
for f in files: # root's: libvirt makes them swtpm's when the VM starts
proxy.upload_volume(tpm_pool, f.dev, get_file(proxy, tpool, f.volume), owner=(0, 0), mode="0600")
disks = {f.dev: (op.intent["paths"][f.dev], f.format) for f in backup.files.filter(role=BackupFile.DISK)}
proxy._defineXML(restore_over_definition(proxy._XMLDesc(PERSISTENT_XML), disks))
if op.intent["autostart"]:
proxy.instance.setAutostart(1)
return {"open": reverse("instances:instance", args=[backup.instance_id])}
def progress(self, op):
disks = Backup.objects.filter(uuid=op.params["backup"]).values_list("files__dev", "files__capacity", "files__role")
copied = set(op.intent.get("copied", []))
sizes = {dev: capacity for dev, capacity, role in disks if role == BackupFile.DISK}
return sum(c for dev, c in sizes.items() if dev in copied), sum(sizes.values())
def reconcile(self, op):
backup = _backup(op.params)
instance = Instance.objects.select_related("compute").get(pk=backup.instance_id)
if instance.compute_id != op.intent["compute"]:
return Outcome(Operation.UNCERTAIN, error=say(_(
"The VM moved to another compute; check its disks and the restore's copies, then resolve this job")))
proxy = _proxy(instance)
if op.intent.get("switching"):
current = etree.fromstring(proxy._XMLDesc(PERSISTENT_XML))
if {d.find("target").get("dev"): d.xpath("string(source/@file)")
for d in current.xpath("devices/disk[@device='disk']")} == op.intent["paths"]:
# defined: the switch is done; the VM may have run since, its NVRAM and TPM are not replaced again
if op.intent["autostart"]:
proxy.instance.setAutostart(1)
return Outcome(Operation.SUCCEEDED, result={"open": reverse("instances:instance", args=[instance.pk])})
if proxy.get_status() != VIR_DOMAIN_SHUTOFF or proxy.instance.hasManagedSaveImage(0):
return Outcome(Operation.UNCERTAIN, error=say(_(
"The VM was started while its disks were being replaced; check its disks, then resolve this job")))
row = _target_row(backup.target, instance.compute)
return Outcome(Operation.SUCCEEDED,
result=self._switch(op, backup, proxy, target_pool(proxy, row.pool, row.pool_uuid)))
volumes = {dev: name for dev, (_pool, name) in op.intent["over"]["disks"].items()}
if op.intent.get("copying"): # libvirt's answer to that copy is unknown
return Outcome(Operation.UNCERTAIN, error=say(_(
"A disk was being copied when the job stopped; check this volume, then resolve this job: %(volumes)s"),
volumes=volumes[op.intent["copying"]]))
pools = proxy.file_pools()
for dev in op.intent.get("copied", []):
pool = op.intent["over"]["disks"][dev][0]
if pool not in pools: # recovery waits: the copies are removed once it runs
raise util.OperationError(_("Storage pool %(pool)s is not active; the restore's copies in it are "
"removed when it is"), pool=pool)
pools[pool][0].refresh(0)
remove_files(pools[pool][0], [volumes[dev]])
ended = Operation.CANCELLED if op.cancel_requested else Operation.FAILED
return Outcome(ended, error=say(_("The VM keeps its disks; the restore's copies were removed")))
def log_entry(self, op, state):
return _log(op, state, f"restored over from its backup taken {op.intent['time']}")
def _vm_page(op):
vm = Instance.objects.get(compute_id=op.intent["compute"], uuid=op.intent["uuid"])
return reverse("instances:instance", args=[vm.pk])

View file

@ -0,0 +1,312 @@
"""backup.restore_over: a ready backup restored over its own shut-off VM.
The disks are copied as new volumes, the old ones stay; then the switch
(NVRAM, TPM state, the disks' sources), recorded first and finished by
recovery."""
import contextlib
import hashlib
from types import SimpleNamespace
from unittest.mock import MagicMock, patch
from uuid import uuid4
import libvirt
from django.contrib.auth import get_user_model
from django.test import TransactionTestCase
from django.utils import timezone
from lxml import etree
from appsettings.settings import get_settings
from computes.models import Compute
from instances.models import Instance
from operations import jobs
from operations.jobs import Context
from operations.models import Claim, Operation, acquire
from vmbackups.jobs import RestoreOver, _owner
from vmbackups.models import Backup, BackupFile, BackupTarget, BackupTargetPool
from vrtManager.util import OperationError
GIB = 1024**3
WORKER = "wvc-test:1:a"
NVRAM = "/var/lib/libvirt/qemu/nvram/vm1_VARS.fd"
CURRENT = (
"<domain type='kvm'><name>vm1</name><uuid>51515151-0000-4000-8000-000000000001</uuid>"
f"<os><type arch='x86_64' machine='q35'>hvm</type><nvram>{NVRAM}</nvram></os><devices>"
"<disk type='file' device='disk'><driver name='qemu' type='qcow2'/><source file='/pool/vm1.qcow2'/><target dev='vda'/></disk>"
"<interface type='network'><mac address='52:54:00:00:00:01'/><source network='default'/></interface>"
"</devices></domain>"
)
def error(code):
err = libvirt.libvirtError("x")
err.err = (code,)
return err
class RestoreOverTests(TransactionTestCase):
def setUp(self):
get_settings()
self.admin = get_user_model().objects.create_superuser("ro_admin", "a@example.com", "pw")
self.compute = Compute.objects.create(name="h1", hostname="192.0.2.51", login="u", password="p", type=1)
self.vm = Instance.objects.create(compute=self.compute, name="vm1", uuid="51515151-0000-4000-8000-000000000001")
self.target = BackupTarget.objects.create(name="nfs1")
BackupTargetPool.objects.create(target=self.target, compute=self.compute, pool="b1", pool_uuid="u")
self.backup = Backup.objects.create(target=self.target, instance=self.vm, vm_uuid=self.vm.uuid, vm_name="vm1",
compute_name="h1", state=Backup.READY,
manifest={"nvram": "copied", "tpm": "none"})
Backup.objects.filter(pk=self.backup.pk).update(created_at=timezone.make_aware(timezone.datetime(2026, 11, 17, 11, 40)))
self.backup.refresh_from_db()
prefix = self.backup.prefix
self.files = {f"{prefix}-nvram.fd": b"vars", f"{prefix}-tpm-tpm2-00.permall": b"state"}
BackupFile.objects.create(backup=self.backup, role=BackupFile.DISK, dev="vda", volume=f"{prefix}-vda.qcow2",
format="qcow2", capacity=GIB)
self.add_small(BackupFile.NVRAM, "", f"{prefix}-nvram.fd")
self.proxy = MagicMock()
self.proxy.get_status.return_value = libvirt.VIR_DOMAIN_SHUTOFF
self.proxy.instance.snapshotNum.return_value = 0
self.proxy.instance.name.return_value = "vm1"
self.proxy.instance.autostart.return_value = 0
self.proxy.instance.hasManagedSaveImage.return_value = 0
self.proxy.instance.UUIDString.return_value = self.vm.uuid
self.proxy.get_tpm.return_value = None
self.proxy.backup_plan.return_value = {
"disks": [{"dev": "vda", "path": "/pool/vm1.qcow2", "pool": "default", "format": "qcow2", "capacity": GIB}],
"nvram": NVRAM, "tpm": False}
self.proxy._XMLDesc.return_value = CURRENT
self.dest = MagicMock()
self.dest.name.return_value = "default"
self.dest.info.return_value = [2, 100 * GIB, 0, 100 * GIB]
self.dest.storageVolLookupByName.side_effect = error(libvirt.VIR_ERR_NO_STORAGE_VOL)
self.proxy.file_pools.return_value = {"default": (self.dest, "/pool")}
self.nvram_pool, self.tpm_pool = MagicMock(), MagicMock()
self.tpm_pool.listVolumes.return_value = [".lock", "tpm2-00.permall"]
self.proxy._nvram_pool.side_effect = lambda: contextlib.nullcontext(self.nvram_pool)
self.proxy._tpm_pool.side_effect = lambda uuid, build=False: contextlib.nullcontext(self.tpm_pool)
self.events = []
self.proxy.upload_volume.side_effect = lambda pool, name, data, **kw: self.events.append(("upload", name, data, kw))
self.proxy._defineXML.side_effect = lambda xml: self.events.append(("define", xml))
self.tpool = MagicMock()
self.tpool.storageVolLookupByName.return_value.info.return_value = [0, GIB, GIB]
self.storage = MagicMock()
self.storage.clone_volume.side_effect = lambda vol, name, **kw: f"/pool/{name}"
self.removed = []
for name, value in (
("vmbackups.jobs.wvmBackup", MagicMock(return_value=self.proxy)),
("vmbackups.jobs.target_pool", MagicMock(return_value=self.tpool)),
("vmbackups.jobs.get_file", MagicMock(side_effect=lambda conn, pool, name: self.files[name])),
("vmbackups.jobs.wvmStorage", MagicMock(return_value=self.storage)),
("vmbackups.jobs.remove_files", MagicMock(side_effect=self.remove)),
):
patcher = patch(name, value)
patcher.start()
self.addCleanup(patcher.stop)
def add_small(self, role, dev, volume):
data = self.files[volume]
BackupFile.objects.create(backup=self.backup, role=role, dev=dev, volume=volume, size=len(data),
sha256=hashlib.sha256(data).hexdigest())
def remove(self, pool, names):
names = list(names)
self.removed.extend(names)
self.events.append(("remove", names))
def with_tpm(self):
self.backup.manifest = {"nvram": "copied", "tpm": "copied"}
self.backup.save()
self.add_small(BackupFile.TPM, "tpm2-00.permall", f"{self.backup.prefix}-tpm-tpm2-00.permall")
self.proxy.get_tpm.return_value = "emulator"
self.proxy.backup_plan.return_value["tpm"] = True
def submit(self):
op = jobs.submit("backup.restore_over", self.admin, {"backup": str(self.backup.uuid)}, f"key-{uuid4().hex[:12]}")
acquire(WORKER, "wvc-test")
Operation.objects.filter(pk=op.pk).update(state=Operation.RUNNING, worker=WORKER)
op.refresh_from_db()
return op
def run_job(self, op):
return RestoreOver().run(op, Context(op, SimpleNamespace(identity=WORKER)))
def interrupted(self, op):
with self.assertRaises(Exception):
self.run_job(op)
op.refresh_from_db()
return op
def refused(self, *texts):
with self.assertRaises(OperationError) as caught:
self.run_job(self.submit())
for text in texts:
self.assertIn(text, str(caught.exception))
self.storage.clone_volume.assert_not_called()
def defined(self):
return etree.fromstring(next(e[1] for e in self.events if e[0] == "define"))
def test_the_disks_are_copied_as_new_volumes_then_switched(self):
op = self.submit()
self.assertEqual(op.intent["over"]["disks"], {"vda": ["default", "vm1-vda-20261117-1140.qcow2"]})
self.assertTrue(Claim.objects.filter(operation=op, resource=f"volume:{self.compute.pk}:default/vm1-vda-20261117-1140.qcow2",
mode=Claim.EXCLUSIVE).exists())
self.assertTrue(Claim.objects.filter(operation=op, resource=f"instance:{self.vm.uuid}", mode=Claim.EXCLUSIVE).exists())
self.run_job(op)
self.storage.clone_volume.assert_called_once()
self.assertEqual(self.storage.clone_volume.call_args.args[1], "vm1-vda-20261117-1140.qcow2")
tree = self.defined()
self.assertEqual(tree.xpath("devices/disk/source/@file"), ["/pool/vm1-vda-20261117-1140.qcow2"])
self.assertEqual(tree.xpath("devices/interface/mac/@address"), ["52:54:00:00:00:01"]) # the VM's own
# the NVRAM file replaced in place, before the define
self.assertEqual(self.events[0], ("remove", ["vm1_VARS.fd"]))
self.assertEqual(self.events[1], ("upload", "vm1_VARS.fd", b"vars", {"owner": _owner(), "mode": "0600"}))
self.assertEqual(self.events[-1][0], "define")
op.refresh_from_db()
self.assertTrue(op.intent["switching"])
self.assertNotIn("/pool/vm1.qcow2", self.removed) # the old volume stays
def test_the_tpm_state_is_replaced(self):
self.with_tpm()
self.run_job(self.submit())
self.assertIn(("remove", ["tpm2-00.permall"]), self.events) # not swtpm's .lock
self.assertIn(("upload", "tpm2-00.permall", b"state", {"owner": (0, 0), "mode": "0600"}), self.events)
self.proxy._tpm_pool.assert_called_with(self.vm.uuid, build=True)
def test_state_never_written_is_removed(self):
self.backup.files.filter(role=BackupFile.NVRAM).delete()
self.backup.manifest = {"nvram": "never written", "tpm": "never written"}
self.backup.save()
self.proxy.get_tpm.return_value = "emulator"
self.proxy.backup_plan.return_value["tpm"] = True
self.run_job(self.submit())
self.assertIn(("remove", ["vm1_VARS.fd"]), self.events)
self.assertIn(("remove", ["tpm2-00.permall"]), self.events)
self.assertEqual([e for e in self.events if e[0] == "upload"], [])
def test_a_running_vm_is_refused(self):
self.proxy.get_status.return_value = libvirt.VIR_DOMAIN_RUNNING
with self.assertRaisesMessage(OperationError, "Shut the VM down"):
self.submit()
def test_a_vm_with_snapshots_is_refused(self):
self.proxy.instance.snapshotNum.return_value = 2
with self.assertRaisesMessage(OperationError, "snapshots"):
self.submit()
def test_other_disks_are_refused(self):
self.proxy.backup_plan.return_value["disks"].append(
{"dev": "vdb", "path": "/pool/vm1-b.raw", "pool": "default", "format": "raw", "capacity": GIB})
with self.assertRaisesMessage(OperationError, "vdb"):
self.submit()
def test_firmware_or_tpm_changed_since_the_backup_is_refused(self):
self.proxy.backup_plan.return_value["nvram"] = None
with self.assertRaisesMessage(OperationError, "UEFI"):
self.submit()
self.proxy.backup_plan.return_value["nvram"] = NVRAM
self.proxy.backup_plan.return_value["tpm"] = True
with self.assertRaisesMessage(OperationError, "TPM"):
self.submit()
def test_a_backup_without_its_vm_is_refused(self):
Backup.objects.filter(pk=self.backup.pk).update(instance=None)
with self.assertRaisesMessage(OperationError, "new VM"):
self.submit()
def test_a_taken_name_is_refused_and_nothing_removed(self):
self.dest.storageVolLookupByName.side_effect = None # restored over from this backup before
self.refused("vm1-vda-20261117-1140.qcow2")
self.assertEqual(self.removed, [])
def test_disks_changed_after_the_job_was_queued_are_refused(self):
op = self.submit()
self.proxy.backup_plan.return_value["disks"][0]["pool"] = "other"
with self.assertRaisesMessage(OperationError, "changed"):
self.run_job(op)
def test_a_vm_started_before_the_switch_stops_it_and_the_copies_go(self):
self.storage.clone_volume.side_effect = lambda vol, name, **kw: (
setattr(self.proxy.get_status, "return_value", libvirt.VIR_DOMAIN_RUNNING) or f"/pool/{name}")
op = self.interrupted(self.submit())
self.assertNotIn("switching", op.intent)
outcome = RestoreOver().reconcile(op)
self.assertEqual(outcome.state, Operation.FAILED)
self.assertIn("vm1-vda-20261117-1140.qcow2", self.removed)
self.assertEqual([e for e in self.events if e[0] in ("upload", "define")], [])
def test_recovery_finishes_a_switch(self):
self.proxy._defineXML.side_effect = RuntimeError("worker gone")
op = self.interrupted(self.submit())
self.assertTrue(op.intent["switching"])
self.proxy._defineXML.side_effect = lambda xml: self.events.append(("define", xml))
self.events.clear()
self.assertEqual(RestoreOver().reconcile(op).state, Operation.SUCCEEDED)
self.assertEqual(self.defined().xpath("devices/disk/source/@file"), ["/pool/vm1-vda-20261117-1140.qcow2"])
self.assertNotIn("vm1-vda-20261117-1140.qcow2", self.removed)
def test_recovery_of_a_done_switch_changes_nothing_again(self):
op = self.submit()
self.run_job(op)
op.refresh_from_db()
# the VM booted outside the panel after the define, before the job's end was recorded
self.proxy._XMLDesc.return_value = self.events[-1][1]
self.events.clear()
self.assertEqual(RestoreOver().reconcile(op).state, Operation.SUCCEEDED)
self.assertEqual(self.events, [])
def test_a_saved_state_made_during_the_copy_stops_the_switch(self):
def copy(vol, name, **kw):
self.proxy.backup_plan.side_effect = OperationError("vm1 has a saved state")
return f"/pool/{name}"
self.storage.clone_volume.side_effect = copy
op = self.interrupted(self.submit())
self.assertNotIn("switching", op.intent)
self.assertEqual([e for e in self.events if e[0] in ("upload", "define")], [])
def test_recovery_of_a_vm_moved_is_uncertain(self):
self.proxy._defineXML.side_effect = RuntimeError("worker gone")
op = self.interrupted(self.submit())
Instance.objects.filter(pk=self.vm.pk).update(compute=Compute.objects.create(
name="h2", hostname="192.0.2.52", login="u", password="p", type=1))
self.assertEqual(RestoreOver().reconcile(op).state, Operation.UNCERTAIN)
def test_recovery_of_a_switch_on_a_started_vm_is_uncertain(self):
self.proxy._defineXML.side_effect = RuntimeError("worker gone")
op = self.interrupted(self.submit())
self.proxy.get_status.return_value = libvirt.VIR_DOMAIN_RUNNING
self.assertEqual(RestoreOver().reconcile(op).state, Operation.UNCERTAIN)
def test_a_copy_in_flight_is_uncertain(self):
self.storage.clone_volume.side_effect = RuntimeError("worker gone")
op = self.interrupted(self.submit())
self.assertEqual(RestoreOver().reconcile(op).state, Operation.UNCERTAIN)
self.assertEqual(self.removed, [])
def test_the_log_row(self):
op = self.submit()
self.run_job(op)
entry = RestoreOver().log_entry(op, Operation.SUCCEEDED)
self.assertEqual(entry[:3], ("h1", "vm1", self.vm.uuid))
self.assertEqual(entry[3], "VM vm1: restored over from its backup taken 2026-11-17 11:40")
def test_autostart_is_off_during_the_switch(self):
self.proxy.instance.autostart.return_value = 1
self.proxy.instance.setAutostart.side_effect = lambda on: self.events.append(("autostart", on))
self.run_job(self.submit())
kinds = [e[0] for e in self.events]
self.assertEqual(self.events[0], ("autostart", 0)) # a host booting mid-switch starts nothing
self.assertEqual(self.events[-1], ("autostart", 1))
self.assertLess(kinds.index("define"), len(kinds) - 1)
def test_recovery_of_a_switch_on_a_saved_vm_is_uncertain(self):
self.proxy._defineXML.side_effect = RuntimeError("worker gone")
op = self.interrupted(self.submit())
self.proxy.instance.hasManagedSaveImage.return_value = 1
self.assertEqual(RestoreOver().reconcile(op).state, Operation.UNCERTAIN)
def test_a_copy_libvirt_refused_fails_and_removes_the_copies(self):
self.storage.clone_volume.side_effect = libvirt.libvirtError("No space left on device")
op = self.interrupted(self.submit())
self.assertEqual(RestoreOver().reconcile(op).state, Operation.FAILED)
self.assertIn("vm1-vda-20261117-1140.qcow2", self.removed) # libvirt may have made it before failing

View file

@ -215,6 +215,33 @@ def manifest_names(pool):
return sorted(name for name in pool.listVolumes() if name.startswith("wvc-") and name.endswith("-manifest.json"))
def set_disk_sources(tree, disks):
"""Each disk of the definition tree a restored file (disks: {dev: (path,
format)}), with nothing of the old one's chain."""
for disk in tree.xpath("devices/disk[@device='disk']"):
path, disk_format = disks[disk.find("target").get("dev")]
disk.set("type", "file")
for old in disk.xpath("source|backingStore"):
disk.remove(old)
driver = disk.find("driver")
if driver is None:
driver = etree.SubElement(disk, "driver", name="qemu")
driver.set("type", disk_format)
source = etree.Element("source", file=path)
disk.insert(list(disk).index(driver) + 1, source)
def restore_over_definition(definition, disks):
"""The VM's own definition with its disks the restored files: the rest of
it (devices, MACs, NVRAM path) is the VM's current one, but for a new
generation ID, as the guest is rolled back."""
tree = etree.fromstring(definition)
set_disk_sources(tree, disks)
if (genid := tree.find("genid")) is not None:
genid.text = None # libvirt makes a new one
return etree.tostring(tree).decode()
def restore_definition(definition, *, name, uuid, macs, disks, nvram, connect):
"""A backup's kept definition made a new VM's: rewrite_for_new_vm's
changes (macs: one per NIC, in order), its media ejected, a new generation ID, each disk's
@ -231,17 +258,7 @@ def restore_definition(definition, *, name, uuid, macs, disks, nvram, connect):
source.getparent().remove(source)
if (genid := tree.find("genid")) is not None:
genid.text = None # libvirt makes a new one
for disk in tree.xpath("devices/disk[@device='disk']"):
path, disk_format = disks[disk.find("target").get("dev")]
disk.set("type", "file")
for old in disk.xpath("source|backingStore"):
disk.remove(old)
driver = disk.find("driver")
if driver is None:
driver = etree.SubElement(disk, "driver", name="qemu")
driver.set("type", disk_format)
source = etree.Element("source", file=path)
disk.insert(list(disk).index(driver) + 1, source)
set_disk_sources(tree, disks)
if (element := tree.find("os/nvram")) is not None:
if element.find("source") is not None:
element.find("source").set("file", nvram)

View file

@ -340,6 +340,27 @@ class RestoreDefinitionTestCase(unittest.TestCase):
self.assertEqual(self.restored(connect=True).xpath("devices/interface/link/@state"), ["up"])
class RestoreOverDefinitionTestCase(unittest.TestCase):
def test_only_the_disks_sources_change(self):
from lxml import etree
from vrtManager.backup import restore_over_definition
tree = etree.fromstring(restore_over_definition(SOURCE, {"vda": ("/pool/vm1-vda-20261117-1140.qcow2", "qcow2"),
"vdb": ("/pool/vm1-vdb-20261117-1140.raw", "raw")}))
self.assertEqual(tree.xpath("devices/disk[@device='disk']/source/@file"),
["/pool/vm1-vda-20261117-1140.qcow2", "/pool/vm1-vdb-20261117-1140.raw"])
self.assertEqual(tree.xpath("devices/disk//backingStore"), [])
source = etree.fromstring(SOURCE)
for path in ("name", "uuid", "os/nvram", "title"):
self.assertEqual(tree.findtext(path), source.findtext(path))
self.assertEqual(tree.xpath("devices/interface/mac/@address"), source.xpath("devices/interface/mac/@address"))
self.assertEqual(len(tree.xpath("devices/disk[@device='cdrom']/source")), 2) # the VM's media stay
# the guest sees it was rolled back: libvirt makes a new generation ID
self.assertEqual(tree.findtext("genid") or "", "")
self.assertIsNotNone(tree.find("genid"))
class RestoreHostTestCase(unittest.TestCase):
def conn(self):
conn = MagicMock()