diff --git a/README.md b/README.md index a94ccc96..93f8e774 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ WebVirtCloud and `virt-manager`/`virsh` can manage the same libvirt host **concu * Cloud-init datasource interface (OpenStack metadata compatible) and NoCloud seed media * REST API — OpenAPI 3.0 (Swagger & ReDoc), with API tokens * LDAP / Active Directory integration (optional) +* VM backups, of a running or shut-off VM, into a storage pool of your choice; a backup is restored as a new VM * Daily backups of the panel, with an optional off-site copy (restic over SFTP) * English, Turkish and Simplified Chinese @@ -58,7 +59,7 @@ WebVirtCloud and `virt-manager`/`virsh` can manage the same libvirt host **concu 1. [Installation](#installation): [installer](#installer), [Docker](#docker), [manual](#manual-installation), [first login](#first-login) 2. [Adding a Compute Node](#adding-a-compute-node) 3. [Configuration](#configuration): [environment variables](#environment-variables), [HTTPS and reverse proxy](#https-and-reverse-proxy), [cloud-init datasource](#cloud-init-datasource), [LDAP](#ldap), [OTP](#two-factor-login-otp), [serial console](#serial-console) -4. [Backups](#backups): [off-site copy](#off-site-copy) +4. [Backups](#backups): [off-site copy](#off-site-copy), [VM backups](#vm-backups) 5. [Updating](#updating): [Docker](#docker-1), [installer and manual](#installer-and-manual-installation), [restore and rollback](#restore-and-rollback), [moving to a new machine](#moving-to-a-new-machine), [behavior changes](#behavior-changes) 6. [Usage](#usage): [users and permissions](#users-roles-and-permissions), [REST API](#rest-api), [screenshots](#screenshots) 7. [Development](#development) @@ -585,6 +586,27 @@ b=$(find /root/offsite-restore -type d -name 'webvirtcloud-backup-*' | sort | ta and follow [Moving to a new machine](#moving-to-a-new-machine) with that `b` (leave out its `b=` line). +### 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 and a manifest. It is restored as a new VM, with its network disconnected unless asked, on a host that has the target's pool. After the panel's database is lost, add the target again and use **Read backups from target**. + +VMs with TPM state, host devices, shared host directories, or encrypted or non-file disks are not backed up; CD-ROMs are left out. + +The target must be: + +- on storage apart from the VMs' disks: a target on the same storage is lost with it; +- writable by QEMU; +- with NFS on SELinux hosts, allowed: `setsebool -P virt_use_nfs 1`. + +An NFS target, on each host: + +```bash +virsh pool-define-as vmbackups netfs --source-host nfs.example.com --source-path /export/vmbackups --target /var/lib/libvirt/vmbackups +virsh pool-build vmbackups && virsh pool-start vmbackups && virsh pool-autostart vmbackups +``` + +The panel does not copy VM backups off site: the target's storage does. + ## Updating Every update starts with a backup in its own directory (mode 700, named by date) that holds the database, the commit it was taken from, for Docker the TLS client certificates and, for installer and manual installations, `settings.py`, the nginx config, `/etc/default/webvirtcloud` if there is one and migrations an old installer generated (`local-migrations.tar`). The database is copied with SQLite's backup API, which also finishes a write interrupted by a crash. This covers sqlite only; with PostgreSQL (`WEBVIRTCLOUD_DB_HOST`), back up that database yourself before updating. diff --git a/doc/permissions.md b/doc/permissions.md index f5eb7d0a..70b4ffc0 100644 --- a/doc/permissions.md +++ b/doc/permissions.md @@ -23,6 +23,7 @@ WebVirtCloud combines three kinds of access rights: | Delete the VM | ✅ | ✅ | `is_delete` | ❌ | | Disks and media (add, attach, edit, detach, delete volumes; CD-ROM/ISO) | ✅ | ❌ | — | ❌ | | Network interfaces, boot options, vCPU hotplug, autostart, guest agent, suspend/resume, migrate, raw XML, owners | ✅ | ❌ | — | ❌ | +| Backups: back up, restore, delete; backup targets | ✅ | ❌ | — | ❌ | Notes: diff --git a/locale/tr/LC_MESSAGES/django.mo b/locale/tr/LC_MESSAGES/django.mo index 77b4ecfb..9d1397b6 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 09d91326..c106ba7d 100644 --- a/locale/tr/LC_MESSAGES/django.po +++ b/locale/tr/LC_MESSAGES/django.po @@ -542,7 +542,7 @@ msgstr "Kullanıcıya anahtar ekleme formu" #: instances/templates/create_flavors.html:20 #: instances/templates/instances/boot_device.html:17 #: networks/templates/network.html:134 nwfilters/templates/nwfilter.html:45 -#: vmbackups/templates/vmbackups/target.html:49 +#: vmbackups/templates/vmbackups/target.html:59 #: vmbackups/templates/vmbackups/targets.html:40 msgid "Add" msgstr "Ekle" @@ -3266,7 +3266,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:83 +#: instances/jobs.py:73 vmbackups/jobs.py:84 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ı" @@ -3287,17 +3287,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:499 +#: instances/jobs.py:206 instances/jobs.py:646 vmbackups/jobs.py:502 #, python-format msgid "Instance '%(clone_name)s' already exists!" msgstr "'%(clone_name)s' sanal makinesi zaten mevcut!" -#: instances/jobs.py:208 vmbackups/jobs.py:501 +#: instances/jobs.py:208 vmbackups/jobs.py:504 #, 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:503 +#: instances/jobs.py:211 vmbackups/jobs.py:506 #, python-format msgid "Instance name '%(clone_name)s' contains invalid characters!" msgstr "Sanal makine adı '%(clone_name)s' geçersiz karakterler içermektedir!" @@ -3454,11 +3454,11 @@ msgid "Clone VM" msgstr "Sanal makineyi klonla" #: instances/jobs.py:656 instances/jobs.py:663 instances/jobs.py:1005 -#: vmbackups/jobs.py:220 vmbackups/jobs.py:603 +#: vmbackups/jobs.py:221 vmbackups/jobs.py:606 msgid "Copying disks" msgstr "Diskler kopyalanıyor" -#: instances/jobs.py:715 vmbackups/jobs.py:296 +#: instances/jobs.py:715 vmbackups/jobs.py:297 msgid "libvirt has no result of the copy" msgstr "libvirt'te kopyanın sonucu yok" @@ -3471,7 +3471,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:302 +#: instances/jobs.py:729 instances/jobs.py:821 vmbackups/jobs.py:303 msgid "The copy failed" msgstr "Kopyalama başarısız oldu" @@ -3493,11 +3493,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:339 +#: instances/jobs.py:801 vmbackups/jobs.py:340 msgid "The job stopped before the copy started" msgstr "İş, kopyalama başlamadan durdu" -#: instances/jobs.py:808 vmbackups/jobs.py:387 +#: instances/jobs.py:808 vmbackups/jobs.py:388 msgid "libvirt is still copying the disks" msgstr "libvirt diskleri hâlâ kopyalıyor" @@ -4359,7 +4359,7 @@ msgstr "Aygıt" #: instances/templates/instances/boot_device.html:14 #: instances/templates/instances/settings_tab.html:685 #: networks/templates/network.html:304 -#: vmbackups/templates/vmbackups/target.html:23 +#: vmbackups/templates/vmbackups/target.html:33 msgid "Remove" msgstr "Kaldır" @@ -9752,17 +9752,17 @@ msgstr "" msgid "Start after restore" msgstr "Geri yüklendikten sonra başlat" -#: vmbackups/jobs.py:56 +#: vmbackups/jobs.py:57 #, 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/jobs.py:66 +#: vmbackups/jobs.py:67 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:70 +#: vmbackups/jobs.py:71 msgid "" "A running VM's backup needs libvirt 11.10 or later; shut the VM down to back " "it up" @@ -9770,35 +9770,35 @@ 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:72 +#: vmbackups/jobs.py:73 msgid "A paused VM's file systems cannot be frozen" msgstr "Duraklatılmış bir sanal makinenin dosya sistemleri dondurulamaz" -#: vmbackups/jobs.py:74 +#: vmbackups/jobs.py:75 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:124 +#: vmbackups/jobs.py:125 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:185 +#: vmbackups/jobs.py:186 msgid "Back up VM" msgstr "Sanal makineyi yedekle" -#: vmbackups/jobs.py:236 vmbackups/jobs.py:303 +#: vmbackups/jobs.py:237 vmbackups/jobs.py:304 msgid "Writing the backup's files" msgstr "Yedeğin dosyaları yazılıyor" -#: vmbackups/jobs.py:315 +#: vmbackups/jobs.py:316 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:364 +#: vmbackups/jobs.py:365 #, python-format msgid "" "The VM is no longer on the compute the job ran on; check these volumes of the" @@ -9807,7 +9807,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:381 +#: vmbackups/jobs.py:382 #, python-format msgid "" "A disk was being copied when the job stopped; check these volumes of the " @@ -9816,7 +9816,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:391 +#: vmbackups/jobs.py:392 #, python-format msgid "" "Another backup runs on the VM; check these volumes of the backup target, then" @@ -9825,7 +9825,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:397 +#: vmbackups/jobs.py:398 #, python-format msgid "" "libvirt has no result of the copy; check these volumes of the backup target, " @@ -9834,68 +9834,68 @@ msgstr "" "libvirt'te kopyanın sonucu yok; yedek hedefindeki şu birimleri kontrol edin, " "sonra bu işi çözün: %(volumes)s" -#: vmbackups/jobs.py:405 +#: vmbackups/jobs.py:406 msgid "The job stopped before the copy ended" msgstr "İş, kopyalama bitmeden durdu" -#: vmbackups/jobs.py:412 +#: vmbackups/jobs.py:413 #, python-format msgid "The backup's files could not be written: %(error)s" msgstr "Yedeğin dosyaları yazılamadı: %(error)s" -#: vmbackups/jobs.py:430 +#: vmbackups/jobs.py:433 #, 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:443 +#: vmbackups/jobs.py:446 msgid "Delete backup" msgstr "Yedeği sil" -#: vmbackups/jobs.py:452 +#: vmbackups/jobs.py:455 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:516 +#: vmbackups/jobs.py:519 #, 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:519 vmbackups/jobs.py:521 +#: vmbackups/jobs.py:522 vmbackups/jobs.py:524 #, 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:531 vmbackups/templates/vmbackups/restore.html:7 +#: vmbackups/jobs.py:534 vmbackups/templates/vmbackups/restore.html:7 msgid "Restore backup" msgstr "Yedeği geri yükle" -#: vmbackups/jobs.py:544 +#: vmbackups/jobs.py:547 msgid "Only a ready backup is restored" msgstr "Yalnızca hazır bir yedek geri yüklenir" -#: vmbackups/jobs.py:574 +#: vmbackups/jobs.py:577 #, 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:582 +#: vmbackups/jobs.py:585 #, 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:599 +#: vmbackups/jobs.py:602 #, python-format msgid "The NVRAM file %(path)s exists already" msgstr "%(path)s NVRAM dosyası zaten var" -#: vmbackups/jobs.py:630 +#: vmbackups/jobs.py:633 #, 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:652 +#: vmbackups/jobs.py:655 #, python-format msgid "" "A disk was being copied when the job stopped; check this volume, then resolve" @@ -9904,7 +9904,7 @@ msgstr "" "İş durduğunda bir disk kopyalanıyordu; bu birimi kontrol edin, sonra bu işi " "çözün: %(volumes)s" -#: vmbackups/jobs.py:657 +#: vmbackups/jobs.py:660 #, python-format msgid "" "Storage pool %(pool)s is not active; the restore's copies in it are removed " @@ -9913,10 +9913,23 @@ msgstr "" "%(pool)s depolama havuzu etkin değil; geri yüklemenin içindeki kopyaları " "havuz etkin olunca kaldırılır" -#: vmbackups/jobs.py:666 +#: vmbackups/jobs.py:669 msgid "The VM was not defined; its copies were removed" msgstr "Sanal makine tanımlanmadı; kopyaları kaldırıldı" +#: vmbackups/jobs.py:688 vmbackups/templates/vmbackups/target.html:18 +msgid "Read backups from target" +msgstr "Yedekleri hedeften oku" + +#: vmbackups/jobs.py:736 +#, python-format +msgid "" +"Not read, as a file of the backup is missing, changed or unreadable: " +"%(names)s" +msgstr "" +"Yedeğin bir dosyası eksik, değişmiş ya da okunamaz olduğu için okunmadı: " +"%(names)s" + #: vmbackups/templates/vmbackups/consistency.html:1 msgid "Shut off" msgstr "Kapalı" @@ -9945,8 +9958,8 @@ msgstr "" "hedeften kaldırılır." #: vmbackups/templates/vmbackups/index.html:10 -#: vmbackups/templates/vmbackups/target.html:6 -#: vmbackups/templates/vmbackups/target.html:8 +#: vmbackups/templates/vmbackups/target.html:7 +#: vmbackups/templates/vmbackups/target.html:9 #: vmbackups/templates/vmbackups/targets.html:6 #: vmbackups/templates/vmbackups/targets.html:8 msgid "Backup targets" @@ -10012,21 +10025,29 @@ 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/target.html:11 +#: vmbackups/templates/vmbackups/target.html:13 #, python-format msgid "%(counter)s backup." msgid_plural "%(counter)s backups." msgstr[0] "%(counter)s yedek." msgstr[1] "%(counter)s yedek." -#: vmbackups/templates/vmbackups/target.html:23 +#: vmbackups/templates/vmbackups/target.html:18 +msgid "" +"Adds the backups whose manifest is in the target and that the panel does not " +"list, as after its database was lost." +msgstr "" +"Manifestosu hedefte olup panelin listelemediği yedekleri ekler; örneğin " +"panelin veritabanı kaybolduktan sonra." + +#: vmbackups/templates/vmbackups/target.html:33 msgid "" "Remove this storage pool from the target? The pool and its files stay on the " "host." msgstr "" "Bu depolama havuzu hedeften çıkarılsın mı? Havuz ve dosyaları sunucuda kalır." -#: vmbackups/templates/vmbackups/target.html:33 +#: vmbackups/templates/vmbackups/target.html:43 #, python-format msgid "" "The target is inside storage pool %(pool)s: its backups are lost with that " @@ -10035,11 +10056,11 @@ msgstr "" "Hedef %(pool)s depolama havuzunun içinde: o depolama kaybolursa yedekler de " "kaybolur." -#: vmbackups/templates/vmbackups/target.html:43 +#: vmbackups/templates/vmbackups/target.html:53 msgid "Add a compute's storage pool" msgstr "Bir sunucunun depolama havuzunu ekle" -#: vmbackups/templates/vmbackups/target.html:45 +#: vmbackups/templates/vmbackups/target.html:55 msgid "" "The pool must be the same directory as the target's other pools, as an NFS " "share mounted on each host." @@ -10047,11 +10068,11 @@ msgstr "" "Havuz, hedefin diğer havuzlarıyla aynı dizin olmalıdır; örneğin her sunucuya " "bağlanmış bir NFS paylaşımı." -#: vmbackups/templates/vmbackups/target.html:58 +#: vmbackups/templates/vmbackups/target.html:68 msgid "Delete this backup target? Its storage pools stay on the hosts." msgstr "Bu yedek hedefi silinsin mi? Depolama havuzları sunucularda kalır." -#: vmbackups/templates/vmbackups/target.html:58 +#: vmbackups/templates/vmbackups/target.html:68 msgid "Delete target" msgstr "Hedefi sil" @@ -10125,12 +10146,12 @@ 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:67 vmbackups/views.py:75 +#: vmbackups/views.py:67 vmbackups/views.py:85 #, 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:92 +#: vmbackups/views.py:102 #, python-format msgid "" "Storage pool %(pool)s of %(compute)s is not the same directory as storage " @@ -10139,7 +10160,7 @@ msgstr "" "%(compute)s sunucusunun %(pool)s depolama havuzu, %(other_compute)s " "sunucusunun %(other)s depolama havuzuyla aynı dizin değil" -#: vmbackups/views.py:124 +#: vmbackups/views.py:134 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 aacd3e07..859c7bfa 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 15d15fdb..316318a3 100644 --- a/locale/zh/LC_MESSAGES/django.po +++ b/locale/zh/LC_MESSAGES/django.po @@ -534,7 +534,7 @@ msgstr "为用户添加密钥表单" #: instances/templates/create_flavors.html:20 #: instances/templates/instances/boot_device.html:17 #: networks/templates/network.html:134 nwfilters/templates/nwfilter.html:45 -#: vmbackups/templates/vmbackups/target.html:49 +#: vmbackups/templates/vmbackups/target.html:59 #: vmbackups/templates/vmbackups/targets.html:40 msgid "Add" msgstr "添加" @@ -3111,7 +3111,7 @@ msgstr "控制台监听的不只是 localhost;只有管理员可以移除其 msgid "The name of the virtual machine must not contain any special characters" msgstr "虚拟机名称不能包含任何特殊字符" -#: instances/jobs.py:73 vmbackups/jobs.py:83 +#: instances/jobs.py:73 vmbackups/jobs.py:84 msgid "The VM moved to another compute after the job was queued" msgstr "任务排队后,虚拟机已移到另一个计算节点" @@ -3132,17 +3132,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:499 +#: instances/jobs.py:206 instances/jobs.py:646 vmbackups/jobs.py:502 #, python-format msgid "Instance '%(clone_name)s' already exists!" msgstr "虚拟机 '%(clone_name)s' 已存在!" -#: instances/jobs.py:208 vmbackups/jobs.py:501 +#: instances/jobs.py:208 vmbackups/jobs.py:504 #, 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:503 +#: instances/jobs.py:211 vmbackups/jobs.py:506 #, python-format msgid "Instance name '%(clone_name)s' contains invalid characters!" msgstr "虚拟机名称 '%(clone_name)s' 包含无效字符!" @@ -3284,11 +3284,11 @@ msgid "Clone VM" msgstr "克隆虚拟机" #: instances/jobs.py:656 instances/jobs.py:663 instances/jobs.py:1005 -#: vmbackups/jobs.py:220 vmbackups/jobs.py:603 +#: vmbackups/jobs.py:221 vmbackups/jobs.py:606 msgid "Copying disks" msgstr "正在复制磁盘" -#: instances/jobs.py:715 vmbackups/jobs.py:296 +#: instances/jobs.py:715 vmbackups/jobs.py:297 msgid "libvirt has no result of the copy" msgstr "libvirt 没有复制的结果" @@ -3299,7 +3299,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:302 +#: instances/jobs.py:729 instances/jobs.py:821 vmbackups/jobs.py:303 msgid "The copy failed" msgstr "复制失败" @@ -3317,11 +3317,11 @@ msgid "" "this job: %(volumes)s" msgstr "克隆的一个卷正在创建中;请检查这些卷,然后处理此任务:%(volumes)s" -#: instances/jobs.py:801 vmbackups/jobs.py:339 +#: instances/jobs.py:801 vmbackups/jobs.py:340 msgid "The job stopped before the copy started" msgstr "任务在复制开始前停止" -#: instances/jobs.py:808 vmbackups/jobs.py:387 +#: instances/jobs.py:808 vmbackups/jobs.py:388 msgid "libvirt is still copying the disks" msgstr "libvirt 仍在复制磁盘" @@ -4148,7 +4148,7 @@ msgstr "设备" #: instances/templates/instances/boot_device.html:14 #: instances/templates/instances/settings_tab.html:685 #: networks/templates/network.html:304 -#: vmbackups/templates/vmbackups/target.html:23 +#: vmbackups/templates/vmbackups/target.html:33 msgid "Remove" msgstr "移除" @@ -9195,152 +9195,163 @@ msgstr "恢复的客户机保留虚拟机的地址和主机名:与原虚拟机 msgid "Start after restore" msgstr "恢复后启动" -#: vmbackups/jobs.py:56 +#: vmbackups/jobs.py:57 #, python-format msgid "Backup target %(target)s has no storage pool on %(compute)s" msgstr "备份目标 %(target)s 在 %(compute)s 上没有存储池" -#: vmbackups/jobs.py:66 +#: vmbackups/jobs.py:67 msgid "The VM must be running, paused or shut off to be backed up" msgstr "虚拟机必须处于运行、暂停或关闭状态才能备份" -#: vmbackups/jobs.py:70 +#: vmbackups/jobs.py:71 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:72 +#: vmbackups/jobs.py:73 msgid "A paused VM's file systems cannot be frozen" msgstr "无法冻结已暂停虚拟机的文件系统" -#: vmbackups/jobs.py:74 +#: vmbackups/jobs.py:75 msgid "The guest agent does not answer: the file systems cannot be frozen" msgstr "客户机代理没有响应:无法冻结文件系统" -#: vmbackups/jobs.py:124 +#: vmbackups/jobs.py:125 msgid "" "The VM's NVRAM file changed while it was backed up; back the VM up again" msgstr "虚拟机的 NVRAM 文件在备份期间发生了变化;请重新备份该虚拟机" -#: vmbackups/jobs.py:185 +#: vmbackups/jobs.py:186 msgid "Back up VM" msgstr "备份虚拟机" -#: vmbackups/jobs.py:236 vmbackups/jobs.py:303 +#: vmbackups/jobs.py:237 vmbackups/jobs.py:304 msgid "Writing the backup's files" msgstr "正在写入备份文件" -#: vmbackups/jobs.py:315 +#: vmbackups/jobs.py:316 msgid "The guest's file systems could not be thawed; trying again" msgstr "无法解冻客户机的文件系统;正在重试" -#: vmbackups/jobs.py:364 +#: vmbackups/jobs.py:365 #, 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:381 +#: vmbackups/jobs.py:382 #, 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:391 +#: vmbackups/jobs.py:392 #, 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:397 +#: vmbackups/jobs.py:398 #, 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:405 +#: vmbackups/jobs.py:406 msgid "The job stopped before the copy ended" msgstr "作业在复制结束前停止" -#: vmbackups/jobs.py:412 +#: vmbackups/jobs.py:413 #, python-format msgid "The backup's files could not be written: %(error)s" msgstr "无法写入备份文件:%(error)s" -#: vmbackups/jobs.py:430 +#: vmbackups/jobs.py:433 #, python-format msgid "No compute of backup target %(target)s reaches its storage pool" msgstr "备份目标 %(target)s 的计算节点都无法访问其存储池" -#: vmbackups/jobs.py:443 +#: vmbackups/jobs.py:446 msgid "Delete backup" msgstr "删除备份" -#: vmbackups/jobs.py:452 +#: vmbackups/jobs.py:455 msgid "This backup is being made; cancel its job to stop it" msgstr "此备份正在创建;要停止它,请取消其作业" -#: vmbackups/jobs.py:516 +#: vmbackups/jobs.py:519 #, python-format msgid "The backup's file %(name)s is missing from the target" msgstr "目标中缺少备份文件 %(name)s" -#: vmbackups/jobs.py:519 vmbackups/jobs.py:521 +#: vmbackups/jobs.py:522 vmbackups/jobs.py:524 #, python-format msgid "The backup's file %(name)s differs from the one written" msgstr "备份文件 %(name)s 与写入的不同" -#: vmbackups/jobs.py:531 vmbackups/templates/vmbackups/restore.html:7 +#: vmbackups/jobs.py:534 vmbackups/templates/vmbackups/restore.html:7 msgid "Restore backup" msgstr "恢复备份" -#: vmbackups/jobs.py:544 +#: vmbackups/jobs.py:547 msgid "Only a ready backup is restored" msgstr "只能恢复就绪的备份" -#: vmbackups/jobs.py:574 +#: vmbackups/jobs.py:577 #, python-format msgid "A VM named %(name)s exists on %(compute)s" msgstr "%(compute)s 上已存在名为 %(name)s 的虚拟机" -#: vmbackups/jobs.py:582 +#: vmbackups/jobs.py:585 #, python-format msgid "This host has no active directory storage pool %(pool)s" msgstr "此主机没有名为 %(pool)s 的活动目录存储池" -#: vmbackups/jobs.py:599 +#: vmbackups/jobs.py:602 #, python-format msgid "The NVRAM file %(path)s exists already" msgstr "NVRAM 文件 %(path)s 已存在" -#: vmbackups/jobs.py:630 +#: vmbackups/jobs.py:633 #, python-format msgid "The VM was restored; it did not start: %(error)s" msgstr "虚拟机已恢复;但未能启动:%(error)s" -#: vmbackups/jobs.py:652 +#: vmbackups/jobs.py:655 #, 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:657 +#: vmbackups/jobs.py:660 #, 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:666 +#: vmbackups/jobs.py:669 msgid "The VM was not defined; its copies were removed" msgstr "虚拟机未定义;其副本已删除" +#: vmbackups/jobs.py:688 vmbackups/templates/vmbackups/target.html:18 +msgid "Read backups from target" +msgstr "从目标读取备份" + +#: vmbackups/jobs.py:736 +#, python-format +msgid "" +"Not read, as a file of the backup is missing, changed or unreadable: " +"%(names)s" +msgstr "由于备份的某个文件缺失、已更改或无法读取,未读取:%(names)s" + #: vmbackups/templates/vmbackups/consistency.html:1 msgid "Shut off" msgstr "已关闭" @@ -9367,8 +9378,8 @@ msgid "" msgstr "要删除 %(vm)s 在 %(time)s 的备份吗?其文件将从目标中移除。" #: vmbackups/templates/vmbackups/index.html:10 -#: vmbackups/templates/vmbackups/target.html:6 -#: vmbackups/templates/vmbackups/target.html:8 +#: vmbackups/templates/vmbackups/target.html:7 +#: vmbackups/templates/vmbackups/target.html:9 #: vmbackups/templates/vmbackups/targets.html:6 #: vmbackups/templates/vmbackups/targets.html:8 msgid "Backup targets" @@ -9432,40 +9443,46 @@ msgid "" "with its own UUID and MAC addresses." msgstr "%(vm)s 在 %(time)s 的备份(位于 %(target)s)将恢复为一台拥有自己 UUID 和 MAC 地址的新虚拟机。" -#: vmbackups/templates/vmbackups/target.html:11 +#: vmbackups/templates/vmbackups/target.html:13 #, python-format msgid "%(counter)s backup." msgid_plural "%(counter)s backups." msgstr[0] "%(counter)s 个备份。" -#: vmbackups/templates/vmbackups/target.html:23 +#: vmbackups/templates/vmbackups/target.html:18 +msgid "" +"Adds the backups whose manifest is in the target and that the panel does not " +"list, as after its database was lost." +msgstr "添加清单位于目标中、但面板未列出的备份,例如在面板数据库丢失之后。" + +#: vmbackups/templates/vmbackups/target.html:33 msgid "" "Remove this storage pool from the target? The pool and its files stay on the " "host." msgstr "要从目标中移除此存储池吗?存储池及其文件仍保留在主机上。" -#: vmbackups/templates/vmbackups/target.html:33 +#: vmbackups/templates/vmbackups/target.html:43 #, python-format msgid "" "The target is inside storage pool %(pool)s: its backups are lost with that " "storage." msgstr "目标位于存储池 %(pool)s 内:该存储丢失时其备份也会丢失。" -#: vmbackups/templates/vmbackups/target.html:43 +#: vmbackups/templates/vmbackups/target.html:53 msgid "Add a compute's storage pool" msgstr "添加计算节点的存储池" -#: vmbackups/templates/vmbackups/target.html:45 +#: vmbackups/templates/vmbackups/target.html:55 msgid "" "The pool must be the same directory as the target's other pools, as an NFS " "share mounted on each host." msgstr "该存储池必须与目标的其他存储池是同一目录,例如挂载在每台主机上的 NFS 共享。" -#: vmbackups/templates/vmbackups/target.html:58 +#: vmbackups/templates/vmbackups/target.html:68 msgid "Delete this backup target? Its storage pools stay on the hosts." msgstr "要删除此备份目标吗?其存储池仍保留在主机上。" -#: vmbackups/templates/vmbackups/target.html:58 +#: vmbackups/templates/vmbackups/target.html:68 msgid "Delete target" msgstr "删除目标" @@ -9530,19 +9547,19 @@ msgstr "存储池 %(pool)s 是备份目标 %(target)s;请先将其从目标中 msgid "No backup target has a storage pool on this VM's host." msgstr "没有备份目标在此虚拟机的主机上有存储池。" -#: vmbackups/views.py:67 vmbackups/views.py:75 +#: vmbackups/views.py:67 vmbackups/views.py:85 #, python-format msgid "Backup target %(target)s has backups; delete them first" msgstr "备份目标 %(target)s 中有备份;请先删除它们" -#: vmbackups/views.py:92 +#: vmbackups/views.py:102 #, 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:124 +#: vmbackups/views.py:134 msgid "Choose a backup target" msgstr "请选择备份目标" diff --git a/vmbackups/jobs.py b/vmbackups/jobs.py index f197131a..98daad22 100644 --- a/vmbackups/jobs.py +++ b/vmbackups/jobs.py @@ -11,6 +11,7 @@ from django.core.exceptions import PermissionDenied from django.urls import reverse from django.db import transaction from django.utils import timezone +from django.utils.dateparse import parse_datetime from django.utils.translation import gettext_noop as _ from lxml import etree from libvirt import VIR_DOMAIN_PAUSED, VIR_DOMAIN_RUNNING, VIR_DOMAIN_SHUTOFF, VIR_ERR_NO_DOMAIN, VIR_ERR_NO_STORAGE_VOL, libvirtError @@ -25,8 +26,8 @@ from operations.jobs import Cancelled, Kind, Outcome, Plan, register 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, put_file, remove_files, - restore_definition, target_pool, volume_exists, wvmBackup) +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) from vrtManager.connection import NVRAM_DIR, wvmConnect from vrtManager.instance import wvmInstance from vrtManager.storage import wvmStorage @@ -420,11 +421,13 @@ class CreateBackup(Kind): def _target_pool(target): - """The target's pool through the first of its computes that reaches it.""" + """(connection, pool) of the target through the first of its computes + that reaches its pool.""" for row in target.pools.select_related("compute").order_by("compute__name"): c = row.compute try: - return target_pool(wvmConnect(c.hostname, c.login, c.password, c.type), row.pool, row.pool_uuid) + conn = wvmConnect(c.hostname, c.login, c.password, c.type) + return conn, target_pool(conn, row.pool, row.pool_uuid) except libvirtError: continue raise util.OperationError(_("No compute of backup target %(target)s reaches its storage pool"), target=target.name) @@ -462,7 +465,7 @@ class DeleteBackup(Kind): def run(self, op, ctx): _superuser(op.user) backup = _backup(op.params) - pool = _target_pool(backup.target) + _conn, pool = _target_pool(backup.target) ctx.record_intent(deleting=True) return self._delete(backup, pool) @@ -481,7 +484,7 @@ class DeleteBackup(Kind): backup = Backup.objects.select_related("target").filter(uuid=op.params["backup"]).first() if backup is None: return Outcome(Operation.SUCCEEDED) - return Outcome(Operation.SUCCEEDED, result=self._delete(backup, _target_pool(backup.target))) + return Outcome(Operation.SUCCEEDED, result=self._delete(backup, _target_pool(backup.target)[1])) def log_entry(self, op, state): backup = f"Backup {op.intent['time']} of {op.intent['vm']}" @@ -503,22 +506,22 @@ def _check_name(name): raise util.OperationError(_("Instance name '%(clone_name)s' contains invalid characters!"), clone_name=name) -def _check_files(conn, pool, backup): - """Each file of the backup is in the target: disks at their size, the - small files with their SHA-256.""" +def _check_files(conn, pool, files): + """Each file of a backup ({role, volume, capacity, sha256}) is in the + target: disks at their size, the small files with their SHA-256.""" pool.refresh(0) - for f in backup.files.all(): + for f in files: try: - vol = pool.storageVolLookupByName(f.volume) + vol = pool.storageVolLookupByName(f["volume"]) except libvirtError as err: if err.get_error_code() != VIR_ERR_NO_STORAGE_VOL: raise - raise util.OperationError(_("The backup's file %(name)s is missing from the target"), name=f.volume) from err - if f.role == BackupFile.DISK: - if vol.info()[1] != f.capacity: - raise util.OperationError(_("The backup's file %(name)s differs from the one written"), name=f.volume) - elif hashlib.sha256(get_file(conn, pool, f.volume)).hexdigest() != f.sha256: - raise util.OperationError(_("The backup's file %(name)s differs from the one written"), name=f.volume) + raise util.OperationError(_("The backup's file %(name)s is missing from the target"), name=f["volume"]) from err + if f["role"] == BackupFile.DISK: + if vol.info()[1] != f["capacity"]: + raise util.OperationError(_("The backup's file %(name)s differs from the one written"), name=f["volume"]) + elif hashlib.sha256(get_file(conn, pool, f["volume"])).hexdigest() != f["sha256"]: + raise util.OperationError(_("The backup's file %(name)s differs from the one written"), name=f["volume"]) @register @@ -574,7 +577,7 @@ class RestoreBackup(Kind): raise util.OperationError(_("A VM named %(name)s exists on %(compute)s"), name=p["name"], compute=compute.name) row = _target_row(backup.target, compute) tpool = target_pool(conn, row.pool, row.pool_uuid) - _check_files(conn, tpool, backup) + _check_files(conn, tpool, backup.files.values("role", "volume", "capacity", "sha256")) definition = get_file(conn, tpool, backup.files.get(role=BackupFile.DOMAIN).volume).decode() check_restore_host(conn, definition) pools = conn.file_pools() @@ -672,3 +675,68 @@ class RestoreBackup(Kind): def _vm_page(op): vm = Instance.objects.get(compute_id=op.intent["compute"], uuid=op.intent["uuid"]) return reverse("instances:instance", args=[vm.pk]) + + +@register +class ImportBackups(Kind): + """The backups of a target read into the panel, as after the panel's + database was lost: each manifest whose backup the panel does not list + is checked as a restore checks it, then added with its files. Nothing + on the target changes.""" + + name = "backup.import" + label = _("Read backups from target") + + def normalize(self, raw): + return {"target": int(raw["target"])} + + def plan(self, user, params): + _superuser(user) + target = BackupTarget.objects.get(pk=params["target"]) + return Plan(claims={claims.backup_target_key(target.pk): Claim.EXCLUSIVE}, + resource=claims.backup_target_key(target.pk), label=target.name, intent={"target": target.name}) + + def run(self, op, ctx): + _superuser(op.user) + target = BackupTarget.objects.get(pk=op.params["target"]) + conn, pool = _target_pool(target) + added, incomplete = 0, [] + for name in manifest_names(pool): + data = get_file(conn, pool, name) + try: + manifest = json.loads(data) + if manifest["format"] != MANIFEST_FORMAT: + raise ValueError(manifest["format"]) + if Backup.objects.filter(uuid=manifest["backup"]).exists(): + continue + _check_files(conn, pool, manifest["files"]) + files = [{k: f[k] for k in ("role", "dev", "volume", "format", "capacity", "size", "sha256")} + for f in manifest["files"]] + vm, created_at = manifest["vm"], parse_datetime(manifest["created_at"]) + if created_at is None: + raise ValueError(manifest["created_at"]) + fields = {"vm_uuid": vm["uuid"], "vm_name": vm["name"], "compute_name": manifest["compute"], + "consistency": manifest["consistency"]} + except (ValueError, KeyError, TypeError, util.OperationError): + # cut short, not a manifest of the panel, or a file missing or changed: the others are still read + incomplete.append(name) + continue + with transaction.atomic(): + backup = Backup.objects.create( + uuid=manifest["backup"], target=target, state=Backup.READY, **fields, + instance=Instance.objects.filter(uuid=fields["vm_uuid"]).first(), + manifest=manifest, finished_at=timezone.now(), size=sum(f["size"] for f in files) + len(data), + ) + # the time it was taken, not read + Backup.objects.filter(pk=backup.pk).update(created_at=created_at) + BackupFile.objects.bulk_create(BackupFile(backup=backup, **f) for f in files) + added += 1 + result = {"added": added} + if incomplete: + result["warning"] = say(_("Not read, as a file of the backup is missing, changed or unreadable: %(names)s"), + names=", ".join(incomplete)) + return result + + def log_entry(self, op, state): + message = f"Backup target {op.intent['target']}: backups read" + return "-", "", "", message if state == Operation.SUCCEEDED else f"{message} ({state})" diff --git a/vmbackups/templates/vmbackups/target.html b/vmbackups/templates/vmbackups/target.html index b61e91f4..b9f72cc8 100644 --- a/vmbackups/templates/vmbackups/target.html +++ b/vmbackups/templates/vmbackups/target.html @@ -2,13 +2,23 @@ {% load i18n %} {% load bootstrap_icons %} {% load django_bootstrap5 %} +{% load operations %} {% block title %}{{ target.name }} - {% trans "Backup targets" %}{% endblock %} {% block page_heading %}{% trans "Backup targets" %} / {{ target.name }}{% endblock page_heading %} {% block content %} -
{% blocktrans count counter=backup_count %}{{ counter }} backup.{% plural %}{{ counter }} backups.{% endblocktrans %}
+