diff --git a/README.md b/README.md index 97929333..0615653a 100644 --- a/README.md +++ b/README.md @@ -588,7 +588,7 @@ and follow [Moving to a new machine](#moving-to-a-new-machine) with that `b` (le ### VM backups -Superusers back a VM up from its **Backups** tab into a backup target: a `dir` or `netfs` storage pool made on each host that sees it, added on **Backups → Backup targets** (another host's pool is accepted only when it is the same directory). A running VM keeps running: its disks are copied from one instant, with its file systems frozen for it when the guest agent answers; a shut-off VM's disks are copied as they are. A backup holds the disks, the VM's definition, its UEFI variables, its TPM state and a manifest; a VM with a TPM is backed up shut off. It is restored as a new VM, with its network disconnected unless asked, on a host that has the target's pool; the new VM gets the backed-up VM's TPM state. After the panel's database is lost, add the target again and use **Read backups from target**. +Superusers back a VM up from its **Backups** tab into a backup target: a `dir` or `netfs` storage pool made on each host that sees it, added on **Backups → Backup targets** (another host's pool is accepted only when it is the same directory). A running VM keeps running: its disks are copied from one instant, with its file systems frozen for it when the guest agent answers; a shut-off VM's disks are copied as they are. A backup holds the disks, the VM's definition, its UEFI variables, its TPM state and a manifest; a VM with a TPM is backed up shut off. It is restored as a new VM, with its network disconnected unless asked, on a host that has the target's pool; the new VM gets the backed-up VM's TPM state. A backup is also restored over its own shut-off VM (its disks copied as new volumes it is switched to, its UEFI variables and TPM state back to the backup's, the old volumes kept until deleted), or one of its disks as a new volume. After the panel's database is lost, add the target again and use **Read backups from target**. VMs with a TPM of their own settings (encryption, a state path), host devices, shared host directories, or encrypted or non-file disks are not backed up; CD-ROMs are left out. diff --git a/locale/tr/LC_MESSAGES/django.mo b/locale/tr/LC_MESSAGES/django.mo index c55954c1..d6c0088e 100644 Binary files a/locale/tr/LC_MESSAGES/django.mo and b/locale/tr/LC_MESSAGES/django.mo differ diff --git a/locale/tr/LC_MESSAGES/django.po b/locale/tr/LC_MESSAGES/django.po index 434321fc..33580e47 100644 --- a/locale/tr/LC_MESSAGES/django.po +++ b/locale/tr/LC_MESSAGES/django.po @@ -11,7 +11,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-11-17 13:00+0000\n" +"POT-Creation-Date: 2026-11-17 13:03+0000\n" "PO-Revision-Date: 2020-11-04 12:00+0000\n" "Last-Translator: catborise , 2020\n" "Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n" @@ -76,7 +76,7 @@ msgstr "Geçersiz anahtar" #: networks/templates/network.html:373 nwfilters/templates/nwfilters.html:29 #: storages/templates/storage.html:123 virtsecrets/forms.py:34 #: virtsecrets/forms.py:36 vmbackups/forms.py:23 vmbackups/forms.py:36 -#: vmbackups/forms.py:57 vmbackups/templates/vmbackups/policies.html:16 +#: vmbackups/forms.py:75 vmbackups/templates/vmbackups/policies.html:16 #: vmbackups/templates/vmbackups/targets.html:17 msgid "Name" msgstr "Ad" @@ -473,7 +473,7 @@ msgstr "%(name)s API anahtarı için işlemler" #: templates/common/confirm_delete.html:5 #: templates/common/confirm_delete.html:9 #: templates/common/confirm_delete.html:26 -#: vmbackups/templates/vmbackups/delete_form.html:2 +#: vmbackups/templates/vmbackups/delete_form.html:11 msgid "Delete" msgstr "Sil" @@ -793,7 +793,8 @@ msgstr "Bellek" #: admin/forms.py:210 instances/models.py:240 #: instances/templates/create_instance_w2.html:118 #: instances/templates/instances/settings_tab.html:25 -#: instances/templates/instances/stats_tab.html:53 +#: instances/templates/instances/stats_tab.html:53 vmbackups/forms.py:53 +#: vmbackups/templates/vmbackups/restore_over.html:18 msgid "Disk" msgstr "Disk" @@ -2129,6 +2130,7 @@ msgstr "Bu sunucular bakımda ve hesaba katılmadı:" #: computes/templates/computes/balance.html:32 #: instances/templates/instances/snapshots_tab.html:18 +#: vmbackups/templates/vmbackups/restore_over.html:18 msgid "Now" msgstr "Şimdi" @@ -3458,8 +3460,8 @@ msgid "Clone VM" msgstr "Sanal makineyi klonla" #: instances/jobs.py:656 instances/jobs.py:663 instances/jobs.py:1005 -#: vmbackups/jobs.py:244 vmbackups/jobs.py:665 vmbackups/jobs.py:829 -#: vmbackups/jobs.py:972 +#: vmbackups/jobs.py:244 vmbackups/jobs.py:665 vmbackups/jobs.py:830 +#: vmbackups/jobs.py:973 msgid "Copying disks" msgstr "Diskler kopyalanıyor" @@ -3955,6 +3957,7 @@ msgstr "Sunucunun bir havuzunda zaten bulunan bir birim." #: instances/templates/create_instance_w2.html:165 #: instances/templates/instances/move_disk.html:16 #: instances/templates/instances/settings_tab.html:223 vmbackups/forms.py:14 +#: vmbackups/forms.py:55 msgid "Storage pool" msgstr "Depolama havuzu" @@ -4565,6 +4568,8 @@ msgstr "İstatistikler" #: vmbackups/templates/vmbackups/index.html:8 #: vmbackups/templates/vmbackups/policies.html:9 #: vmbackups/templates/vmbackups/restore.html:9 +#: vmbackups/templates/vmbackups/restore_disk.html:9 +#: vmbackups/templates/vmbackups/restore_over.html:8 #: vmbackups/templates/vmbackups/targets.html:17 msgid "Backups" msgstr "Yedekler" @@ -9736,7 +9741,7 @@ msgstr "" "Eski değerin yerini hemen alır; bir parolanın şifrelediği veriler yeniden " "şifrelenmez." -#: vmbackups/forms.py:13 vmbackups/forms.py:37 +#: vmbackups/forms.py:13 vmbackups/forms.py:37 vmbackups/forms.py:54 msgid "Compute" msgstr "Sunucu" @@ -9764,44 +9769,48 @@ msgstr "" msgid "Start after restore" msgstr "Geri yüklendikten sonra başlat" -#: vmbackups/forms.py:57 vmbackups/templates/vmbackups/vm_tab.html:13 +#: vmbackups/forms.py:56 +msgid "Volume name" +msgstr "Birim adı" + +#: vmbackups/forms.py:75 vmbackups/templates/vmbackups/vm_tab.html:13 msgid "Backup target" msgstr "Yedek hedefi" -#: vmbackups/forms.py:57 +#: vmbackups/forms.py:75 msgid "Every VM of a compute" msgstr "Bir sunucunun bütün sanal makineleri" -#: vmbackups/forms.py:58 +#: vmbackups/forms.py:76 msgid "Or these VMs" msgstr "Ya da bu sanal makineler" -#: vmbackups/forms.py:58 vmbackups/templates/vmbackups/policies.html:16 +#: vmbackups/forms.py:76 vmbackups/templates/vmbackups/policies.html:16 msgid "Daily at" msgstr "Her gün saat" -#: vmbackups/forms.py:58 +#: vmbackups/forms.py:76 msgid "Backups to keep of each VM" msgstr "Her sanal makineden tutulacak yedek sayısı" -#: vmbackups/forms.py:59 vmbackups/templates/vmbackups/vm_tab.html:21 +#: vmbackups/forms.py:77 vmbackups/templates/vmbackups/vm_tab.html:21 msgid "Require frozen file systems" msgstr "Dosya sistemlerinin dondurulmasını zorunlu kıl" -#: vmbackups/forms.py:59 vmbackups/templates/vmbackups/policies.html:27 +#: vmbackups/forms.py:77 vmbackups/templates/vmbackups/policies.html:27 msgid "Enabled" msgstr "Etkin" -#: vmbackups/forms.py:75 +#: vmbackups/forms.py:93 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:58 +#: vmbackups/forms.py:98 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" -#: vmbackups/forms.py:87 +#: vmbackups/forms.py:105 msgid "Keep one backup at least" msgstr "En az bir yedek tutun" @@ -9938,7 +9947,7 @@ msgstr "Yedeğin TPM durum dosyası %(name)s düz bir dosya adı değil" msgid "Restore backup" msgstr "Yedeği geri yükle" -#: vmbackups/jobs.py:605 vmbackups/jobs.py:788 vmbackups/jobs.py:939 +#: vmbackups/jobs.py:605 vmbackups/jobs.py:789 vmbackups/jobs.py:940 msgid "Only a ready backup is restored" msgstr "Yalnızca hazır bir yedek geri yüklenir" @@ -9947,7 +9956,7 @@ msgstr "Yalnızca hazır bir yedek geri yüklenir" 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 vmbackups/jobs.py:968 +#: vmbackups/jobs.py:643 vmbackups/jobs.py:824 vmbackups/jobs.py:969 #, 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" @@ -9962,7 +9971,7 @@ msgstr "%(path)s NVRAM dosyası zaten var" msgid "The VM was restored; it did not start: %(error)s" msgstr "Sanal makine geri yüklendi; başlamadı: %(error)s" -#: vmbackups/jobs.py:719 vmbackups/jobs.py:898 +#: vmbackups/jobs.py:719 vmbackups/jobs.py:899 #, python-format msgid "" "A disk was being copied when the job stopped; check this volume, then resolve" @@ -9971,7 +9980,7 @@ msgstr "" "İş durduğunda bir disk kopyalanıyordu; bu birimi kontrol edin, sonra bu işi " "çözün: %(volumes)s" -#: vmbackups/jobs.py:724 vmbackups/jobs.py:904 +#: vmbackups/jobs.py:724 vmbackups/jobs.py:905 #, python-format msgid "" "Storage pool %(pool)s is not active; the restore's copies in it are removed " @@ -9984,16 +9993,16 @@ msgstr "" msgid "The VM was not defined; its copies were removed" msgstr "Sanal makine tanımlanmadı; kopyaları kaldırıldı" -#: vmbackups/jobs.py:750 +#: vmbackups/jobs.py:751 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 +#: vmbackups/jobs.py:754 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 +#: vmbackups/jobs.py:759 #, python-format msgid "" "The VM's disks (%(now)s) are not the backup's (%(then)s); restore it as a new" @@ -10002,37 +10011,37 @@ 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 +#: vmbackups/jobs.py:762 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 +#: vmbackups/jobs.py:764 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 +#: vmbackups/jobs.py:779 msgid "Restore backup over the VM" msgstr "Yedeği VM'in üzerine geri yükle" -#: vmbackups/jobs.py:791 +#: vmbackups/jobs.py:792 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 +#: vmbackups/jobs.py:815 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 +#: vmbackups/jobs.py:843 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 +#: vmbackups/jobs.py:844 msgid "Replacing the VM's disks" msgstr "VM'in diskleri değiştiriliyor" -#: vmbackups/jobs.py:881 +#: vmbackups/jobs.py:882 msgid "" "The VM moved to another compute; check its disks and the restore's copies, " "then resolve this job" @@ -10040,7 +10049,7 @@ 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 +#: vmbackups/jobs.py:892 msgid "" "The VM was started while its disks were being replaced; check its disks, then" " resolve this job" @@ -10048,25 +10057,25 @@ msgstr "" "VM'in diskleri değiştirilirken VM başlatıldı; disklerini denetleyin, sonra bu" " işi çözümleyin" -#: vmbackups/jobs.py:909 +#: vmbackups/jobs.py:910 msgid "The VM keeps its disks; the restore's copies were removed" msgstr "VM disklerini koruyor; geri yüklemenin kopyaları silindi" -#: vmbackups/jobs.py:921 +#: vmbackups/jobs.py:922 msgid "Restore a disk of a backup" msgstr "Yedeğin bir diskini geri yükle" -#: vmbackups/jobs.py:932 +#: vmbackups/jobs.py:933 #, python-format msgid "The backup has no disk %(dev)s" msgstr "Yedekte %(dev)s diski yok" -#: vmbackups/jobs.py:942 +#: vmbackups/jobs.py:943 #, python-format msgid "%(name)s is not a volume name" msgstr "%(name)s bir birim adı değil" -#: vmbackups/jobs.py:998 +#: vmbackups/jobs.py:999 #, python-format msgid "" "The disk was being copied when the job stopped; check this volume, then " @@ -10075,15 +10084,15 @@ msgstr "" "İş durduğunda disk kopyalanıyordu; bu birimi denetleyin, sonra bu işi " "çözümleyin: %(volume)s" -#: vmbackups/jobs.py:1001 +#: vmbackups/jobs.py:1002 msgid "The disk was not restored" msgstr "Disk geri yüklenmedi" -#: vmbackups/jobs.py:1022 vmbackups/templates/vmbackups/target.html:18 +#: vmbackups/jobs.py:1023 vmbackups/templates/vmbackups/target.html:18 msgid "Read backups from target" msgstr "Yedekleri hedeften oku" -#: vmbackups/jobs.py:1070 +#: vmbackups/jobs.py:1071 #, python-format msgid "" "Not read, as a file of the backup is missing, changed or unreadable: " @@ -10092,11 +10101,11 @@ msgstr "" "Yedeğin bir dosyası eksik, değişmiş ya da okunamaz olduğu için okunmadı: " "%(names)s" -#: vmbackups/jobs.py:1086 +#: vmbackups/jobs.py:1087 msgid "Check backup target" msgstr "Yedek hedefini denetle" -#: vmbackups/jobs.py:1113 +#: vmbackups/jobs.py:1114 #, python-format msgid "Files of these backups are missing from the target: %(backups)s" msgstr "Şu yedeklerin dosyaları hedefte yok: %(backups)s" @@ -10125,13 +10134,26 @@ msgstr "Dondurulmuş" msgid "Crash-consistent" msgstr "Çökme tutarlı" -#: vmbackups/templates/vmbackups/delete_form.html:1 +#: vmbackups/templates/vmbackups/delete_form.html:4 #: vmbackups/templates/vmbackups/restore.html:9 #: vmbackups/templates/vmbackups/restore.html:18 +#: vmbackups/templates/vmbackups/restore_disk.html:18 msgid "Restore" msgstr "Geri yükle" -#: vmbackups/templates/vmbackups/delete_form.html:3 +#: vmbackups/templates/vmbackups/delete_form.html:6 +msgid "As a new VM" +msgstr "Yeni bir VM olarak" + +#: vmbackups/templates/vmbackups/delete_form.html:7 +msgid "Over the VM" +msgstr "VM'in üzerine" + +#: vmbackups/templates/vmbackups/delete_form.html:8 +msgid "One disk" +msgstr "Tek disk" + +#: vmbackups/templates/vmbackups/delete_form.html:12 #, python-format msgid "" "Delete the backup of %(vm)s taken %(time)s? Its files are removed from the " @@ -10298,6 +10320,62 @@ msgstr "" "%(vm)s sanal makinesinin %(time)s tarihli, %(target)s hedefindeki yedeği " "kendi UUID'si ve MAC adresleriyle yeni bir sanal makine olarak geri yüklenir." +#: vmbackups/templates/vmbackups/restore_disk.html:7 +#: vmbackups/templates/vmbackups/restore_disk.html:9 +msgid "Restore one disk" +msgstr "Tek disk geri yükle" + +#: vmbackups/templates/vmbackups/restore_disk.html:12 +#, python-format +msgid "" +"A disk of the backup of %(vm)s taken %(time)s, in %(target)s, is copied as a " +"new volume, attached to no VM." +msgstr "" +"%(vm)s VM'inin %(time)s tarihli, %(target)s içindeki yedeğinden bir disk, " +"hiçbir VM'e bağlanmadan yeni bir birim olarak kopyalanır." + +#: vmbackups/templates/vmbackups/restore_over.html:6 +#: vmbackups/templates/vmbackups/restore_over.html:8 +#: vmbackups/templates/vmbackups/restore_over.html:33 +msgid "Restore over the VM" +msgstr "VM'in üzerine geri yükle" + +#: vmbackups/templates/vmbackups/restore_over.html:11 +#, python-format +msgid "" +"The backup of %(vm)s taken %(time)s, in %(target)s, is restored over the VM: " +"its disks are copied as new volumes and the VM is switched to them. Its " +"settings, MAC addresses and UUID stay." +msgstr "" +"%(vm)s VM'inin %(time)s tarihli, %(target)s içindeki yedeği VM'in üzerine " +"geri yüklenir: diskleri yeni birimler olarak kopyalanır ve VM bunlara " +"geçirilir. Ayarları, MAC adresleri ve UUID'si aynı kalır." + +#: vmbackups/templates/vmbackups/restore_over.html:18 +msgid "After the restore" +msgstr "Geri yüklemeden sonra" + +#: vmbackups/templates/vmbackups/restore_over.html:26 +msgid "The old volumes stay in their pools until you delete them." +msgstr "Eski birimler siz silene kadar havuzlarında kalır." + +#: vmbackups/templates/vmbackups/restore_over.html:27 +msgid "The UEFI variables return to the backup's." +msgstr "UEFI değişkenleri yedekteki haline döner." + +#: vmbackups/templates/vmbackups/restore_over.html:28 +msgid "The TPM state returns to the backup's." +msgstr "TPM durumu yedekteki haline döner." + +#: vmbackups/templates/vmbackups/restore_over.html:33 +#, python-format +msgid "" +"Restore the backup over %(vm)s? What the VM wrote since the backup is no " +"longer on the disks it runs from." +msgstr "" +"Yedek %(vm)s üzerine geri yüklensin mi? VM'in yedekten sonra yazdıkları, " +"çalışacağı disklerde artık olmaz." + #: vmbackups/templates/vmbackups/state.html:1 msgid "Files of the backup are missing from the target" msgstr "Yedeğin dosyaları hedefte yok" @@ -10419,17 +10497,17 @@ msgid "No backup target has a storage pool on this VM's host." msgstr "" "Hiçbir yedek hedefinin bu sanal makinenin sunucusunda depolama havuzu yok." -#: vmbackups/views.py:68 vmbackups/views.py:89 +#: vmbackups/views.py:69 vmbackups/views.py:90 #, python-format msgid "Backup target %(target)s has backups; delete them first" msgstr "%(target)s yedek hedefinde yedekler var; önce onları silin" -#: vmbackups/views.py:71 +#: vmbackups/views.py:72 #, python-format msgid "Backup target %(target)s has schedules; delete them first" msgstr "%(target)s yedek hedefinin zamanlamaları var; önce onları silin" -#: vmbackups/views.py:106 +#: vmbackups/views.py:107 #, python-format msgid "" "Storage pool %(pool)s of %(compute)s is not the same directory as storage " @@ -10438,7 +10516,7 @@ msgstr "" "%(compute)s sunucusunun %(pool)s depolama havuzu, %(other_compute)s " "sunucusunun %(other)s depolama havuzuyla aynı dizin değil" -#: vmbackups/views.py:138 +#: vmbackups/views.py:139 msgid "Choose a backup target" msgstr "Bir yedek hedefi seçin" diff --git a/locale/zh/LC_MESSAGES/django.mo b/locale/zh/LC_MESSAGES/django.mo index 5e7b97f9..54041b3d 100644 Binary files a/locale/zh/LC_MESSAGES/django.mo and b/locale/zh/LC_MESSAGES/django.mo differ diff --git a/locale/zh/LC_MESSAGES/django.po b/locale/zh/LC_MESSAGES/django.po index 7894b1c6..49b79cc9 100644 --- a/locale/zh/LC_MESSAGES/django.po +++ b/locale/zh/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-11-17 13:00+0000\n" +"POT-Creation-Date: 2026-11-17 13:03+0000\n" "PO-Revision-Date: \n" "Last-Translator: \n" "Language-Team: \n" @@ -73,7 +73,7 @@ msgstr "无效的密钥" #: networks/templates/network.html:373 nwfilters/templates/nwfilters.html:29 #: storages/templates/storage.html:123 virtsecrets/forms.py:34 #: virtsecrets/forms.py:36 vmbackups/forms.py:23 vmbackups/forms.py:36 -#: vmbackups/forms.py:57 vmbackups/templates/vmbackups/policies.html:16 +#: vmbackups/forms.py:75 vmbackups/templates/vmbackups/policies.html:16 #: vmbackups/templates/vmbackups/targets.html:17 msgid "Name" msgstr "名称" @@ -466,7 +466,7 @@ msgstr "API 令牌 %(name)s 的操作" #: templates/common/confirm_delete.html:5 #: templates/common/confirm_delete.html:9 #: templates/common/confirm_delete.html:26 -#: vmbackups/templates/vmbackups/delete_form.html:2 +#: vmbackups/templates/vmbackups/delete_form.html:11 msgid "Delete" msgstr "删除" @@ -770,7 +770,8 @@ msgstr "内存" #: admin/forms.py:210 instances/models.py:240 #: instances/templates/create_instance_w2.html:118 #: instances/templates/instances/settings_tab.html:25 -#: instances/templates/instances/stats_tab.html:53 +#: instances/templates/instances/stats_tab.html:53 vmbackups/forms.py:53 +#: vmbackups/templates/vmbackups/restore_over.html:18 msgid "Disk" msgstr "磁盘" @@ -2044,6 +2045,7 @@ msgstr "这些主机正在维护,未计入:" #: computes/templates/computes/balance.html:32 #: instances/templates/instances/snapshots_tab.html:18 +#: vmbackups/templates/vmbackups/restore_over.html:18 msgid "Now" msgstr "现在" @@ -3288,8 +3290,8 @@ msgid "Clone VM" msgstr "克隆虚拟机" #: instances/jobs.py:656 instances/jobs.py:663 instances/jobs.py:1005 -#: vmbackups/jobs.py:244 vmbackups/jobs.py:665 vmbackups/jobs.py:829 -#: vmbackups/jobs.py:972 +#: vmbackups/jobs.py:244 vmbackups/jobs.py:665 vmbackups/jobs.py:830 +#: vmbackups/jobs.py:973 msgid "Copying disks" msgstr "正在复制磁盘" @@ -3756,6 +3758,7 @@ msgstr "主机存储池中已有的卷。" #: instances/templates/create_instance_w2.html:165 #: instances/templates/instances/move_disk.html:16 #: instances/templates/instances/settings_tab.html:223 vmbackups/forms.py:14 +#: vmbackups/forms.py:55 msgid "Storage pool" msgstr "存储池" @@ -4350,6 +4353,8 @@ msgstr "统计" #: vmbackups/templates/vmbackups/index.html:8 #: vmbackups/templates/vmbackups/policies.html:9 #: vmbackups/templates/vmbackups/restore.html:9 +#: vmbackups/templates/vmbackups/restore_disk.html:9 +#: vmbackups/templates/vmbackups/restore_over.html:8 #: vmbackups/templates/vmbackups/targets.html:17 msgid "Backups" msgstr "备份" @@ -9181,7 +9186,7 @@ msgid "" "encrypted anew." msgstr "新值会立即替换旧值;之前用口令加密的内容不会重新加密。" -#: vmbackups/forms.py:13 vmbackups/forms.py:37 +#: vmbackups/forms.py:13 vmbackups/forms.py:37 vmbackups/forms.py:54 msgid "Compute" msgstr "计算节点" @@ -9207,44 +9212,48 @@ msgstr "恢复的客户机保留虚拟机的地址和主机名:与原虚拟机 msgid "Start after restore" msgstr "恢复后启动" -#: vmbackups/forms.py:57 vmbackups/templates/vmbackups/vm_tab.html:13 +#: vmbackups/forms.py:56 +msgid "Volume name" +msgstr "卷名" + +#: vmbackups/forms.py:75 vmbackups/templates/vmbackups/vm_tab.html:13 msgid "Backup target" msgstr "备份目标" -#: vmbackups/forms.py:57 +#: vmbackups/forms.py:75 msgid "Every VM of a compute" msgstr "某计算节点的所有虚拟机" -#: vmbackups/forms.py:58 +#: vmbackups/forms.py:76 msgid "Or these VMs" msgstr "或这些虚拟机" -#: vmbackups/forms.py:58 vmbackups/templates/vmbackups/policies.html:16 +#: vmbackups/forms.py:76 vmbackups/templates/vmbackups/policies.html:16 msgid "Daily at" msgstr "每天时间" -#: vmbackups/forms.py:58 +#: vmbackups/forms.py:76 msgid "Backups to keep of each VM" msgstr "每台虚拟机保留的备份数" -#: vmbackups/forms.py:59 vmbackups/templates/vmbackups/vm_tab.html:21 +#: vmbackups/forms.py:77 vmbackups/templates/vmbackups/vm_tab.html:21 msgid "Require frozen file systems" msgstr "要求冻结文件系统" -#: vmbackups/forms.py:59 vmbackups/templates/vmbackups/policies.html:27 +#: vmbackups/forms.py:77 vmbackups/templates/vmbackups/policies.html:27 msgid "Enabled" msgstr "已启用" -#: vmbackups/forms.py:75 +#: vmbackups/forms.py:93 msgid "Choose a compute or VMs, not both" msgstr "请选择一个计算节点或若干虚拟机,不能同时选择" -#: vmbackups/forms.py:80 vmbackups/jobs.py:58 +#: vmbackups/forms.py:98 vmbackups/jobs.py:58 #, python-format msgid "Backup target %(target)s has no storage pool on %(compute)s" msgstr "备份目标 %(target)s 在 %(compute)s 上没有存储池" -#: vmbackups/forms.py:87 +#: vmbackups/forms.py:105 msgid "Keep one backup at least" msgstr "至少保留一个备份" @@ -9366,7 +9375,7 @@ msgstr "备份的 TPM 状态文件 %(name)s 不是普通文件名" msgid "Restore backup" msgstr "恢复备份" -#: vmbackups/jobs.py:605 vmbackups/jobs.py:788 vmbackups/jobs.py:939 +#: vmbackups/jobs.py:605 vmbackups/jobs.py:789 vmbackups/jobs.py:940 msgid "Only a ready backup is restored" msgstr "只能恢复就绪的备份" @@ -9375,7 +9384,7 @@ msgstr "只能恢复就绪的备份" msgid "A VM named %(name)s exists on %(compute)s" msgstr "%(compute)s 上已存在名为 %(name)s 的虚拟机" -#: vmbackups/jobs.py:643 vmbackups/jobs.py:823 vmbackups/jobs.py:968 +#: vmbackups/jobs.py:643 vmbackups/jobs.py:824 vmbackups/jobs.py:969 #, python-format msgid "This host has no active directory storage pool %(pool)s" msgstr "此主机没有名为 %(pool)s 的活动目录存储池" @@ -9390,14 +9399,14 @@ msgstr "NVRAM 文件 %(path)s 已存在" msgid "The VM was restored; it did not start: %(error)s" msgstr "虚拟机已恢复;但未能启动:%(error)s" -#: vmbackups/jobs.py:719 vmbackups/jobs.py:898 +#: vmbackups/jobs.py:719 vmbackups/jobs.py:899 #, 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:724 vmbackups/jobs.py:904 +#: vmbackups/jobs.py:724 vmbackups/jobs.py:905 #, python-format msgid "" "Storage pool %(pool)s is not active; the restore's copies in it are removed " @@ -9408,106 +9417,106 @@ msgstr "存储池 %(pool)s 未激活;其中恢复的副本将在其激活后 msgid "The VM was not defined; its copies were removed" msgstr "虚拟机未定义;其副本已删除" -#: vmbackups/jobs.py:750 +#: vmbackups/jobs.py:751 msgid "Shut the VM down to restore a backup over it" msgstr "请先将虚拟机关机,再将备份恢复到其上" -#: vmbackups/jobs.py:753 +#: vmbackups/jobs.py:754 msgid "The VM has snapshots; delete them to restore a backup over it" msgstr "虚拟机有快照;请删除它们后再将备份恢复到其上" -#: vmbackups/jobs.py:758 +#: vmbackups/jobs.py:759 #, 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 +#: vmbackups/jobs.py:762 msgid "The VM's UEFI firmware changed since the backup; restore it as a new VM" msgstr "备份之后虚拟机的 UEFI 固件已更改;请恢复为新虚拟机" -#: vmbackups/jobs.py:763 +#: vmbackups/jobs.py:764 msgid "The VM's TPM changed since the backup; restore it as a new VM" msgstr "备份之后虚拟机的 TPM 已更改;请恢复为新虚拟机" -#: vmbackups/jobs.py:778 +#: vmbackups/jobs.py:779 msgid "Restore backup over the VM" msgstr "将备份恢复到虚拟机上" -#: vmbackups/jobs.py:791 +#: vmbackups/jobs.py:792 msgid "The backup's VM is no longer in the panel; restore it as a new VM" msgstr "备份的虚拟机已不在面板中;请恢复为新虚拟机" -#: vmbackups/jobs.py:814 +#: vmbackups/jobs.py:815 msgid "The VM's disks changed after the job was queued" msgstr "任务排队后虚拟机的磁盘已更改" -#: vmbackups/jobs.py:842 +#: vmbackups/jobs.py:843 msgid "The VM changed while its backup was copied; it keeps its disks" msgstr "复制备份期间虚拟机发生了变化;虚拟机保留其磁盘" -#: vmbackups/jobs.py:843 +#: vmbackups/jobs.py:844 msgid "Replacing the VM's disks" msgstr "正在替换虚拟机的磁盘" -#: vmbackups/jobs.py:881 +#: vmbackups/jobs.py:882 msgid "" "The VM moved to another compute; check its disks and the restore's copies, " "then resolve this job" msgstr "虚拟机已迁移到另一台计算节点;请检查其磁盘和恢复的副本,然后处理此任务" -#: vmbackups/jobs.py:891 +#: vmbackups/jobs.py:892 msgid "" "The VM was started while its disks were being replaced; check its disks, then" " resolve this job" msgstr "替换磁盘期间虚拟机被启动;请检查其磁盘,然后处理此任务" -#: vmbackups/jobs.py:909 +#: vmbackups/jobs.py:910 msgid "The VM keeps its disks; the restore's copies were removed" msgstr "虚拟机保留其磁盘;恢复的副本已删除" -#: vmbackups/jobs.py:921 +#: vmbackups/jobs.py:922 msgid "Restore a disk of a backup" msgstr "恢复备份的一个磁盘" -#: vmbackups/jobs.py:932 +#: vmbackups/jobs.py:933 #, python-format msgid "The backup has no disk %(dev)s" msgstr "备份中没有磁盘 %(dev)s" -#: vmbackups/jobs.py:942 +#: vmbackups/jobs.py:943 #, python-format msgid "%(name)s is not a volume name" msgstr "%(name)s 不是有效的卷名" -#: vmbackups/jobs.py:998 +#: vmbackups/jobs.py:999 #, python-format msgid "" "The disk was being copied when the job stopped; check this volume, then " "resolve this job: %(volume)s" msgstr "任务停止时磁盘正在复制;请检查此卷,然后处理此任务:%(volume)s" -#: vmbackups/jobs.py:1001 +#: vmbackups/jobs.py:1002 msgid "The disk was not restored" msgstr "磁盘未恢复" -#: vmbackups/jobs.py:1022 vmbackups/templates/vmbackups/target.html:18 +#: vmbackups/jobs.py:1023 vmbackups/templates/vmbackups/target.html:18 msgid "Read backups from target" msgstr "从目标读取备份" -#: vmbackups/jobs.py:1070 +#: vmbackups/jobs.py:1071 #, python-format msgid "" "Not read, as a file of the backup is missing, changed or unreadable: " "%(names)s" msgstr "由于备份的某个文件缺失、已更改或无法读取,未读取:%(names)s" -#: vmbackups/jobs.py:1086 +#: vmbackups/jobs.py:1087 msgid "Check backup target" msgstr "检查备份目标" -#: vmbackups/jobs.py:1113 +#: vmbackups/jobs.py:1114 #, python-format msgid "Files of these backups are missing from the target: %(backups)s" msgstr "以下备份的文件在目标中缺失:%(backups)s" @@ -9536,13 +9545,26 @@ msgstr "已冻结" msgid "Crash-consistent" msgstr "崩溃一致" -#: vmbackups/templates/vmbackups/delete_form.html:1 +#: vmbackups/templates/vmbackups/delete_form.html:4 #: vmbackups/templates/vmbackups/restore.html:9 #: vmbackups/templates/vmbackups/restore.html:18 +#: vmbackups/templates/vmbackups/restore_disk.html:18 msgid "Restore" msgstr "恢复" -#: vmbackups/templates/vmbackups/delete_form.html:3 +#: vmbackups/templates/vmbackups/delete_form.html:6 +msgid "As a new VM" +msgstr "作为新虚拟机" + +#: vmbackups/templates/vmbackups/delete_form.html:7 +msgid "Over the VM" +msgstr "覆盖到虚拟机" + +#: vmbackups/templates/vmbackups/delete_form.html:8 +msgid "One disk" +msgstr "单个磁盘" + +#: vmbackups/templates/vmbackups/delete_form.html:12 #, python-format msgid "" "Delete the backup of %(vm)s taken %(time)s? Its files are removed from the " @@ -9702,6 +9724,57 @@ msgid "" "with its own UUID and MAC addresses." msgstr "%(vm)s 在 %(time)s 的备份(位于 %(target)s)将恢复为一台拥有自己 UUID 和 MAC 地址的新虚拟机。" +#: vmbackups/templates/vmbackups/restore_disk.html:7 +#: vmbackups/templates/vmbackups/restore_disk.html:9 +msgid "Restore one disk" +msgstr "恢复单个磁盘" + +#: vmbackups/templates/vmbackups/restore_disk.html:12 +#, python-format +msgid "" +"A disk of the backup of %(vm)s taken %(time)s, in %(target)s, is copied as a " +"new volume, attached to no VM." +msgstr "%(vm)s 于 %(time)s 在 %(target)s 中的备份的一个磁盘将复制为新卷,不挂载到任何虚拟机。" + +#: vmbackups/templates/vmbackups/restore_over.html:6 +#: vmbackups/templates/vmbackups/restore_over.html:8 +#: vmbackups/templates/vmbackups/restore_over.html:33 +msgid "Restore over the VM" +msgstr "恢复到虚拟机上" + +#: vmbackups/templates/vmbackups/restore_over.html:11 +#, python-format +msgid "" +"The backup of %(vm)s taken %(time)s, in %(target)s, is restored over the VM: " +"its disks are copied as new volumes and the VM is switched to them. Its " +"settings, MAC addresses and UUID stay." +msgstr "" +"%(vm)s 于 %(time)s 在 %(target)s 中的备份将恢复到该虚拟机上:其磁盘复制为新卷,虚拟机切换到这些卷。其设置、MAC 地址和 " +"UUID 保持不变。" + +#: vmbackups/templates/vmbackups/restore_over.html:18 +msgid "After the restore" +msgstr "恢复之后" + +#: vmbackups/templates/vmbackups/restore_over.html:26 +msgid "The old volumes stay in their pools until you delete them." +msgstr "旧卷会保留在其存储池中,直到您删除它们。" + +#: vmbackups/templates/vmbackups/restore_over.html:27 +msgid "The UEFI variables return to the backup's." +msgstr "UEFI 变量恢复为备份中的状态。" + +#: vmbackups/templates/vmbackups/restore_over.html:28 +msgid "The TPM state returns to the backup's." +msgstr "TPM 状态恢复为备份中的状态。" + +#: vmbackups/templates/vmbackups/restore_over.html:33 +#, python-format +msgid "" +"Restore the backup over %(vm)s? What the VM wrote since the backup is no " +"longer on the disks it runs from." +msgstr "将备份恢复到 %(vm)s 上?备份之后虚拟机写入的内容将不在其运行的磁盘上。" + #: vmbackups/templates/vmbackups/state.html:1 msgid "Files of the backup are missing from the target" msgstr "备份的文件在目标中缺失" @@ -9806,24 +9879,24 @@ msgstr "存储池 %(pool)s 是备份目标 %(target)s;请先将其从目标中 msgid "No backup target has a storage pool on this VM's host." msgstr "没有备份目标在此虚拟机的主机上有存储池。" -#: vmbackups/views.py:68 vmbackups/views.py:89 +#: vmbackups/views.py:69 vmbackups/views.py:90 #, python-format msgid "Backup target %(target)s has backups; delete them first" msgstr "备份目标 %(target)s 中有备份;请先删除它们" -#: vmbackups/views.py:71 +#: vmbackups/views.py:72 #, python-format msgid "Backup target %(target)s has schedules; delete them first" msgstr "备份目标 %(target)s 有计划;请先删除它们" -#: vmbackups/views.py:106 +#: vmbackups/views.py:107 #, python-format msgid "" "Storage pool %(pool)s of %(compute)s is not the same directory as storage " "pool %(other)s of %(other_compute)s" msgstr "%(compute)s 的存储池 %(pool)s 与 %(other_compute)s 的存储池 %(other)s 不是同一目录" -#: vmbackups/views.py:138 +#: vmbackups/views.py:139 msgid "Choose a backup target" msgstr "请选择备份目标" diff --git a/vmbackups/api.py b/vmbackups/api.py index e82102f2..56a1a026 100644 --- a/vmbackups/api.py +++ b/vmbackups/api.py @@ -10,7 +10,8 @@ from operations.api.serializers import OperationSerializer from webvirtcloud.serializers import ErrorSerializer from .models import Backup -from .serializers import BackupSerializer, CreateBackupSerializer, RestoreBackupSerializer, SubmissionSerializer +from .serializers import (BackupSerializer, CreateBackupSerializer, RestoreBackupSerializer, RestoreDiskSerializer, + SubmissionSerializer) def _accepted(request, op): @@ -54,3 +55,23 @@ class BackupViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.G key = data.pop("submission_key") raw = {**data, "backup": str(backup.uuid), "compute": data["compute"].pk} return _accepted(request, jobs.submit("backup.restore", request.user, raw, key)) + + @extend_schema(request=SubmissionSerializer, responses={202: OperationSerializer, 409: ErrorSerializer}) + @action(detail=True, methods=["post"], url_path="restore-over") + def restore_over(self, request, uuid=None): + backup = self.get_object() + serializer = SubmissionSerializer(data=request.data) + serializer.is_valid(raise_exception=True) + key = serializer.validated_data["submission_key"] + return _accepted(request, jobs.submit("backup.restore_over", request.user, {"backup": str(backup.uuid)}, key)) + + @extend_schema(request=RestoreDiskSerializer, responses={202: OperationSerializer, 400: dict, 409: ErrorSerializer}) + @action(detail=True, methods=["post"], url_path="restore-disk") + def restore_disk(self, request, uuid=None): + backup = self.get_object() + serializer = RestoreDiskSerializer(data=request.data) + serializer.is_valid(raise_exception=True) + data = dict(serializer.validated_data) + key = data.pop("submission_key") + raw = {**data, "backup": str(backup.uuid), "compute": data["compute"].pk} + return _accepted(request, jobs.submit("backup.restore_disk", request.user, raw, key)) diff --git a/vmbackups/forms.py b/vmbackups/forms.py index 2fd49bb4..56cf4dcc 100644 --- a/vmbackups/forms.py +++ b/vmbackups/forms.py @@ -47,6 +47,24 @@ class RestoreForm(forms.Form): self.fields["name"].initial = f"{backup.vm_name}-restored" +class RestoreDiskForm(forms.Form): + """One disk of a backup restored as a new volume, attached to no VM.""" + + dev = forms.ChoiceField(label=_("Disk")) + compute = forms.ModelChoiceField(Compute.objects.none(), label=_("Compute")) + pool = forms.CharField(label=_("Storage pool"), max_length=128, initial="default") + name = forms.CharField(label=_("Volume name"), max_length=255) + + def __init__(self, *args, backup, **kwargs): + super().__init__(*args, **kwargs) + disks = list(backup.files.filter(role="disk").order_by("dev")) + self.fields["dev"].choices = [(d.dev, d.dev) for d in disks] + self.fields["compute"].queryset = Compute.objects.filter(backuptargetpool__target=backup.target).order_by("name") + if disks: + first = disks[0] + self.fields["name"].initial = f"{backup.vm_name}-{first.dev}-restored.{'qcow2' if first.format == 'qcow2' else 'raw'}" + + class PolicyForm(forms.ModelForm): """A backup schedule: a compute's VMs or chosen VMs, all on hosts that have a pool of its target.""" diff --git a/vmbackups/jobs.py b/vmbackups/jobs.py index 702e4325..fab04678 100644 --- a/vmbackups/jobs.py +++ b/vmbackups/jobs.py @@ -743,7 +743,8 @@ class RestoreBackup(Kind): 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}. + volume name]}, "old": {dev: the disk's path now}, "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: @@ -764,7 +765,7 @@ def _over_plan(backup, proxy): 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"]} + "old": {dev: now[dev]["path"] for dev in files}, "nvram": plan["nvram"], "tpm": plan["tpm"]} @register diff --git a/vmbackups/serializers.py b/vmbackups/serializers.py index aca57718..4f05cf6e 100644 --- a/vmbackups/serializers.py +++ b/vmbackups/serializers.py @@ -34,6 +34,14 @@ class SubmissionSerializer(serializers.Serializer): submission_key = serializers.CharField(write_only=True) +class RestoreDiskSerializer(serializers.Serializer): + dev = serializers.CharField(max_length=32) + compute = serializers.PrimaryKeyRelatedField(queryset=Compute.objects.all()) + pool = serializers.CharField(default="default") + name = serializers.CharField(max_length=255) + submission_key = serializers.CharField(write_only=True) + + class RestoreBackupSerializer(serializers.Serializer): compute = serializers.PrimaryKeyRelatedField(queryset=Compute.objects.all()) pool = serializers.CharField(default="default") diff --git a/vmbackups/templates/vmbackups/delete_form.html b/vmbackups/templates/vmbackups/delete_form.html index cf9c6370..889e9e22 100644 --- a/vmbackups/templates/vmbackups/delete_form.html +++ b/vmbackups/templates/vmbackups/delete_form.html @@ -1,3 +1,12 @@ -{% load i18n %}{% load operations %}{% load bootstrap_icons %}{% if backup.state == "ready" %}{% trans "Restore" %}{% endif %}{% if backup.state != "creating" %}
{% csrf_token %}{% submission_key %} +{% load i18n %}{% load operations %}{% load bootstrap_icons %}{% if backup.state == "ready" %}
+ {# fixed: the menu would be cut off by the table's scrolling box #} + + +
{% endif %}{% if backup.state != "creating" %}{% csrf_token %}{% submission_key %}
{% endif %} diff --git a/vmbackups/templates/vmbackups/restore_disk.html b/vmbackups/templates/vmbackups/restore_disk.html new file mode 100644 index 00000000..8bc24723 --- /dev/null +++ b/vmbackups/templates/vmbackups/restore_disk.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} +{% load i18n %} +{% load bootstrap_icons %} +{% load django_bootstrap5 %} +{% load operations %} + +{% block title %}{% trans "Restore one disk" %}{% endblock %} + +{% block page_heading %}{% trans "Backups" %} / {% trans "Restore one disk" %}{% endblock page_heading %} + +{% block content %} +

{% blocktrans with vm=backup.vm_name time=backup.created_at|date:"Y-m-d H:i" target=backup.target.name %}A disk of the backup of {{ vm }} taken {{ time }}, in {{ target }}, is copied as a new volume, attached to no VM.{% endblocktrans %}

+
+
+
+ {% csrf_token %}{% submission_key %} + {% bootstrap_form form %} + +
+
+
+{% endblock %} diff --git a/vmbackups/templates/vmbackups/restore_over.html b/vmbackups/templates/vmbackups/restore_over.html new file mode 100644 index 00000000..b4a7f266 --- /dev/null +++ b/vmbackups/templates/vmbackups/restore_over.html @@ -0,0 +1,38 @@ +{% extends "base.html" %} +{% load i18n %} +{% load bootstrap_icons %} +{% load operations %} + +{% block title %}{% trans "Restore over the VM" %}{% endblock %} + +{% block page_heading %}{% trans "Backups" %} / {% trans "Restore over the VM" %}{% endblock page_heading %} + +{% block content %} +

{% blocktrans with vm=backup.vm_name time=backup.created_at|date:"Y-m-d H:i" target=backup.target.name %}The backup of {{ vm }} taken {{ time }}, in {{ target }}, is restored over the VM: its disks are copied as new volumes and the VM is switched to them. Its settings, MAC addresses and UUID stay.{% endblocktrans %}

+ {% if problem %} +
{% bs_icon 'exclamation-triangle' %} {{ problem }}
+ {% else %} +
+
+ + + + {% for disk in disks %} + + {% endfor %} + +
{% trans "Disk" %}{% trans "Now" %}{% trans "After the restore" %}
{{ disk.dev }}{{ disk.old }}{{ disk.pool }} / {{ disk.name }}
+
    +
  • {% trans "The old volumes stay in their pools until you delete them." %}
  • + {% if over.nvram %}
  • {% trans "The UEFI variables return to the backup's." %}
  • {% endif %} + {% if over.tpm %}
  • {% trans "The TPM state returns to the backup's." %}
  • {% endif %} +
+
+ {% csrf_token %}{% submission_key %} + +
+
+
+ {% endif %} +{% endblock %} diff --git a/vmbackups/tests/test_delete.py b/vmbackups/tests/test_delete.py index e186ccff..0b1003b3 100644 --- a/vmbackups/tests/test_delete.py +++ b/vmbackups/tests/test_delete.py @@ -143,6 +143,19 @@ class IndexTests(TransactionTestCase): self.assertIn("db1", self.rows("?state=failed")[0]) self.assertEqual(self.rows("?state=ready&vm=db"), []) + def test_the_restore_menu_offers_over_the_vm_only_with_its_vm(self): + self.client.force_login(self.admin) + page = lxml_html.fromstring(self.client.get(reverse("vmbackups:index")).content) + links = page.xpath("//table[@id='backups']//a[contains(@class, 'dropdown-item')]/@href") + ready = Backup.objects.get(vm_name="web1") + self.assertEqual(links, [reverse("vmbackups:restore", args=[ready.uuid]), + reverse("vmbackups:restore_over", args=[ready.uuid]), + reverse("vmbackups:restore_disk", args=[ready.uuid])]) + Backup.objects.filter(pk=ready.pk).update(instance=None) + page = lxml_html.fromstring(self.client.get(reverse("vmbackups:index")).content) + self.assertNotIn(reverse("vmbackups:restore_over", args=[ready.uuid]), + page.xpath("//table[@id='backups']//a/@href")) + def test_only_superusers(self): user = get_user_model().objects.create_user("idx_user", password="pw") self.client.force_login(user) diff --git a/vmbackups/tests/test_restore_disk.py b/vmbackups/tests/test_restore_disk.py index 6559f284..b7d98d86 100644 --- a/vmbackups/tests/test_restore_disk.py +++ b/vmbackups/tests/test_restore_disk.py @@ -133,3 +133,24 @@ class RestoreDiskTests(TransactionTestCase): self.assertEqual(entry[0], "h1") self.assertEqual(entry[3], "VM vm1: disk vdb of the backup taken 2026-11-17 11:40 restored as vm1-vdb-restored.raw " "in default") + + def test_the_page_submits_the_job(self): + from lxml import html as lxml_html + + self.client.force_login(self.admin) + url = reverse("vmbackups:restore_disk", args=[self.backup.uuid]) + page = lxml_html.fromstring(self.client.get(url).content) + self.assertEqual(page.xpath("//select[@name='dev']/option/@value"), ["vdb"]) + self.assertEqual(page.xpath("string(//input[@name='name']/@value)"), "vm1-vdb-restored.raw") + response = self.client.post(url, {"dev": "vdb", "compute": self.compute.pk, "pool": "default", + "name": "vm1-vdb-restored.raw", "submission_key": "key-page-disk1"}) + op = Operation.objects.get(kind="backup.restore_disk") + self.assertRedirects(response, reverse("operations:job", args=[op.pk]), fetch_redirect_response=False) + + def test_api_restore_disk(self): + self.client.force_login(self.admin) + response = self.client.post(f"/api/v1/backups/{self.backup.uuid}/restore-disk/", + {"dev": "vdb", "compute": self.compute.pk, "name": "x.raw", "submission_key": "key-api-disk1"}, + content_type="application/json") + self.assertEqual(response.status_code, 202, response.content) + self.assertEqual(response.json()["kind"], "backup.restore_disk") diff --git a/vmbackups/tests/test_restore_over.py b/vmbackups/tests/test_restore_over.py index c13ac148..4917d9b2 100644 --- a/vmbackups/tests/test_restore_over.py +++ b/vmbackups/tests/test_restore_over.py @@ -310,3 +310,43 @@ class RestoreOverTests(TransactionTestCase): 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 + + def test_the_page_shows_the_volumes_then_submits(self): + from django.urls import reverse + from lxml import html as lxml_html + + self.client.force_login(self.admin) + url = reverse("vmbackups:restore_over", args=[self.backup.uuid]) + page = lxml_html.fromstring(self.client.get(url).content) + row = [" ".join(td.text_content().split()) for td in page.xpath("//table[@id='restore-over-disks']/tbody/tr/td")] + self.assertEqual(row, ["vda", "/pool/vm1.qcow2", "default / vm1-vda-20261117-1140.qcow2"]) + self.assertIn("UEFI", page.text_content()) + response = self.client.post(url, {"submission_key": "key-page-over1"}) + op = Operation.objects.get(kind="backup.restore_over") + self.assertRedirects(response, reverse("operations:job", args=[op.pk]), fetch_redirect_response=False) + + def test_the_page_says_why_not(self): + from django.urls import reverse + + self.proxy.get_status.return_value = libvirt.VIR_DOMAIN_RUNNING + self.client.force_login(self.admin) + response = self.client.get(reverse("vmbackups:restore_over", args=[self.backup.uuid])) + self.assertContains(response, "Shut the VM down") + self.assertNotContains(response, "key-") # no form + + def test_only_superusers_and_a_backup_with_its_vm(self): + from django.urls import reverse + + url = reverse("vmbackups:restore_over", args=[self.backup.uuid]) + self.client.force_login(get_user_model().objects.create_user("ro_user", password="pw")) + self.assertEqual(self.client.get(url).status_code, 403) + self.client.force_login(self.admin) + Backup.objects.filter(pk=self.backup.pk).update(instance=None) + self.assertEqual(self.client.get(url).status_code, 404) + + def test_api_restore_over(self): + self.client.force_login(self.admin) + response = self.client.post(f"/api/v1/backups/{self.backup.uuid}/restore-over/", {"submission_key": "key-api-over1"}, + content_type="application/json") + self.assertEqual(response.status_code, 202, response.content) + self.assertEqual(response.json()["kind"], "backup.restore_over") diff --git a/vmbackups/urls.py b/vmbackups/urls.py index fa9ca4e7..a948dd5b 100644 --- a/vmbackups/urls.py +++ b/vmbackups/urls.py @@ -8,6 +8,8 @@ urlpatterns = [ path("", views.index, name="index"), path("/delete/", views.delete, name="delete"), path("/restore/", views.restore, name="restore"), + path("/restore-over/", views.restore_over, name="restore_over"), + path("/restore-disk/", views.restore_disk, name="restore_disk"), path("schedules/", views.policies, name="policies"), path("schedules//", views.policy, name="policy"), path("targets/", views.targets, name="targets"), diff --git a/vmbackups/views.py b/vmbackups/views.py index 76381644..a45adb63 100644 --- a/vmbackups/views.py +++ b/vmbackups/views.py @@ -19,7 +19,8 @@ from vrtManager.backup import pool_space, target_pool from vrtManager.connection import wvmConnect from vrtManager.util import OperationError -from .forms import PolicyForm, RestoreForm, TargetForm, TargetPoolForm +from .forms import PolicyForm, RestoreDiskForm, RestoreForm, TargetForm, TargetPoolForm +from .jobs import _over_plan, _proxy from .models import Backup, BackupPolicy, BackupTarget from .utils import inside_vm_pool @@ -195,6 +196,50 @@ def restore(request, uuid): return render(request, "vmbackups/restore.html", {"backup": backup, "form": form}) +def _submit(request, kind, raw): + """The job, or None with the reason shown.""" + try: + return jobs.submit(kind, request.user, raw, request.POST.get("submission_key", "")) + except claims.Busy as busy: + messages.error(request, busy_message(busy, request.user)) + except (jobs.SubmissionConflict, libvirtError, OperationError) as err: + messages.error(request, error_text(request, err)) + return None + + +@superuser_only +def restore_over(request, uuid): + """Restore a ready backup over its own shut-off VM, after the page shows + which volumes it makes: a backup.restore_over job, followed on its page.""" + backup = get_object_or_404(Backup.objects.select_related("target", "instance__compute"), uuid=uuid, + state=Backup.READY, instance__isnull=False) + if request.method == "POST" and (op := _submit(request, "backup.restore_over", {"backup": str(backup.uuid)})): + return redirect("operations:job", op.pk) + over, problem = None, None + try: + over = _over_plan(backup, _proxy(backup.instance)) + except (OperationError, libvirtError) as err: + problem = error_text(request, err) + disks = [{"dev": dev, "old": over["old"][dev], "pool": pool, "name": name} + for dev, (pool, name) in sorted(over["disks"].items())] if over else [] + return render(request, "vmbackups/restore_over.html", {"backup": backup, "disks": disks, "over": over, + "problem": problem}) + + +@superuser_only +def restore_disk(request, uuid): + """Restore one disk of a ready backup as a new volume: a backup.restore_disk job, followed on its page.""" + backup = get_object_or_404(Backup.objects.select_related("target"), uuid=uuid, state=Backup.READY) + form = RestoreDiskForm(request.POST or None, backup=backup) + if form.is_valid(): + data = form.cleaned_data + raw = {"backup": str(backup.uuid), "dev": data["dev"], "compute": data["compute"].pk, "pool": data["pool"], + "name": data["name"]} + if op := _submit(request, "backup.restore_disk", raw): + return redirect("operations:job", op.pk) + return render(request, "vmbackups/restore_disk.html", {"backup": backup, "form": form}) + + @superuser_only def policies(request): """The backup schedules, and a new one; the superuser who saves one is its owner, whom its jobs run as."""