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

feat(vmbackups): the schedule form sets how often a backup is full

The schedule form gains 'A full backup every N backups' (1: every backup
is full), and the backup lists mark incremental backups. The README says
which backups are incremental and what makes the next one full.
This commit is contained in:
catborise 2026-11-17 17:05:50 +03:00
parent d856ccca68
commit 1b0a54e3d1
9 changed files with 90 additions and 33 deletions

View file

@ -592,7 +592,7 @@ Superusers back a VM up from its **Backups** tab into a backup target: a `dir` o
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.
**Backups → Schedules** backs VMs up every day: chosen VMs or every VM of a compute, into a target, at a time in the panel's time zone (`TZ`), keeping the newest backups of each VM up to a number. The job worker starts each VM's backup within 6 hours of the time, one copy at a time per target, and waits for a host in maintenance; a VM not started in that window waits for the next day. Older backups of a schedule are deleted; backups taken by hand are not. Each target is checked once a day: a backup whose files are gone is marked missing.
**Backups → Schedules** backs VMs up every day: chosen VMs or every VM of a compute, into a target, at a time in the panel's time zone (`TZ`), keeping the newest backups of each VM up to a number. The job worker starts each VM's backup within 6 hours of the time, one copy at a time per target, and waits for a host in maintenance; a VM not started in that window waits for the next day. Older backups of a schedule are deleted; backups taken by hand are not. With "A full backup every N backups" above 1, a schedule's backups of a running VM with qcow2 disks between two full ones copy only what changed since the previous one; each is restored like a full one, and a chain of them is deleted once all of it is beyond the number kept. A migration, a restore over the VM or a shut-off VM's backup makes the next one full. Each target is checked once a day: a backup whose files are gone is marked missing.
The target must be:

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 14:03+0000\n"
"POT-Creation-Date: 2026-11-17 14:05+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"
@ -2466,7 +2466,7 @@ msgstr "hiçbiri"
#: networks/templates/network.html:337 networks/templates/network.html:379
#: networks/templates/network.html:406 networks/templates/network.html:445
#: nwfilters/templates/nwfilter.html:157 templates/common/form.html:28
#: vmbackups/templates/vmbackups/policy_form.html:18
#: vmbackups/templates/vmbackups/policy_form.html:19
msgid "Save"
msgstr "Kaydet"
@ -9793,24 +9793,36 @@ msgstr "Her gün saat"
msgid "Backups to keep of each VM"
msgstr "Her sanal makineden tutulacak yedek sayısı"
#: vmbackups/forms.py:77 vmbackups/templates/vmbackups/vm_tab.html:21
#: vmbackups/forms.py:77
msgid "A full backup every N backups"
msgstr "Her N yedekte bir tam yedek"
#: vmbackups/forms.py:78 vmbackups/templates/vmbackups/vm_tab.html:21
msgid "Require frozen file systems"
msgstr "Dosya sistemlerinin dondurulmasını zorunlu kıl"
#: vmbackups/forms.py:77 vmbackups/templates/vmbackups/policies.html:27
#: vmbackups/forms.py:78 vmbackups/templates/vmbackups/policies.html:27
msgid "Enabled"
msgstr "Etkin"
#: vmbackups/forms.py:93
#: vmbackups/forms.py:90
msgid ""
"1: every backup is full. Above 1, the backups between copy only what changed "
"(running VMs with qcow2 disks)."
msgstr ""
"1: her yedek tamdır. 1'den büyükse aradaki yedekler yalnızca değişenleri "
"kopyalar (qcow2 diskli, çalışan VM'ler)."
#: vmbackups/forms.py:97
msgid "Choose a compute or VMs, not both"
msgstr "Bir sunucu ya da sanal makineler seçin, ikisini birden değil"
#: vmbackups/forms.py:98 vmbackups/jobs.py:58
#: vmbackups/forms.py:102 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:105
#: vmbackups/forms.py:109
msgid "Keep one backup at least"
msgstr "En az bir yedek tutun"
@ -10143,6 +10155,14 @@ msgstr "Dondurulmuş"
msgid "Crash-consistent"
msgstr "Çökme tutarlı"
#: vmbackups/templates/vmbackups/consistency.html:1
msgid "Copies only what changed since the backup it builds on"
msgstr "Yalnızca dayandığı yedekten sonra değişenleri kopyalar"
#: vmbackups/templates/vmbackups/consistency.html:1
msgid "Incremental"
msgstr "Artımlı"
#: vmbackups/templates/vmbackups/delete_form.html:4
#: vmbackups/templates/vmbackups/restore.html:9
#: vmbackups/templates/vmbackups/restore.html:18
@ -10310,15 +10330,17 @@ msgstr "Henüz çalışma yok."
msgid "Time zone: %(time_zone)s"
msgstr "Saat dilimi: %(time_zone)s"
#: vmbackups/templates/vmbackups/policy_form.html:17
#: vmbackups/templates/vmbackups/policy_form.html:18
msgid ""
"Each VM is backed up once a day, starting at the time; a VM that has not "
"started within 6 hours waits for the next day. Older backups of each VM "
"beyond the number kept are deleted; backups taken by hand are not."
"beyond the number kept are deleted, a chain of incremental backups once all "
"of it is beyond; backups taken by hand are not."
msgstr ""
"Her sanal makine günde bir kez, bu saatten başlayarak yedeklenir; 6 saat "
"içinde başlamayan bir sanal makine ertesi günü bekler. Her sanal makinenin "
"tutulan sayıyı aşan eski yedekleri silinir; elle alınan yedekler silinmez."
"Her VM günde bir kez, belirtilen saatte başlayarak yedeklenir; 6 saat içinde "
"başlamayan VM ertesi günü bekler. Her VM'in tutulan sayının dışında kalan "
"eski yedekleri silinir; artımlı yedek zinciri ise tamamı bu sayının dışına "
"çıkınca silinir. Elle alınan yedekler silinmez."
#: vmbackups/templates/vmbackups/restore.html:12
#, python-format

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 14:03+0000\n"
"POT-Creation-Date: 2026-11-17 14:05+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
@ -2358,7 +2358,7 @@ msgstr "无"
#: networks/templates/network.html:337 networks/templates/network.html:379
#: networks/templates/network.html:406 networks/templates/network.html:445
#: nwfilters/templates/nwfilter.html:157 templates/common/form.html:28
#: vmbackups/templates/vmbackups/policy_form.html:18
#: vmbackups/templates/vmbackups/policy_form.html:19
msgid "Save"
msgstr "保存"
@ -9236,24 +9236,34 @@ msgstr "每天时间"
msgid "Backups to keep of each VM"
msgstr "每台虚拟机保留的备份数"
#: vmbackups/forms.py:77 vmbackups/templates/vmbackups/vm_tab.html:21
#: vmbackups/forms.py:77
msgid "A full backup every N backups"
msgstr "每 N 次备份进行一次完整备份"
#: vmbackups/forms.py:78 vmbackups/templates/vmbackups/vm_tab.html:21
msgid "Require frozen file systems"
msgstr "要求冻结文件系统"
#: vmbackups/forms.py:77 vmbackups/templates/vmbackups/policies.html:27
#: vmbackups/forms.py:78 vmbackups/templates/vmbackups/policies.html:27
msgid "Enabled"
msgstr "已启用"
#: vmbackups/forms.py:93
#: vmbackups/forms.py:90
msgid ""
"1: every backup is full. Above 1, the backups between copy only what changed "
"(running VMs with qcow2 disks)."
msgstr "1:每次备份都是完整备份。大于 1 时,中间的备份只复制变化的部分(适用于使用 qcow2 磁盘的运行中虚拟机)。"
#: vmbackups/forms.py:97
msgid "Choose a compute or VMs, not both"
msgstr "请选择一个计算节点或若干虚拟机,不能同时选择"
#: vmbackups/forms.py:98 vmbackups/jobs.py:58
#: vmbackups/forms.py:102 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:105
#: vmbackups/forms.py:109
msgid "Keep one backup at least"
msgstr "至少保留一个备份"
@ -9554,6 +9564,14 @@ msgstr "已冻结"
msgid "Crash-consistent"
msgstr "崩溃一致"
#: vmbackups/templates/vmbackups/consistency.html:1
msgid "Copies only what changed since the backup it builds on"
msgstr "只复制其所依赖的备份之后变化的部分"
#: vmbackups/templates/vmbackups/consistency.html:1
msgid "Incremental"
msgstr "增量"
#: vmbackups/templates/vmbackups/delete_form.html:4
#: vmbackups/templates/vmbackups/restore.html:9
#: vmbackups/templates/vmbackups/restore.html:18
@ -9719,12 +9737,15 @@ msgstr "还没有运行记录。"
msgid "Time zone: %(time_zone)s"
msgstr "时区:%(time_zone)s"
#: vmbackups/templates/vmbackups/policy_form.html:17
#: vmbackups/templates/vmbackups/policy_form.html:18
msgid ""
"Each VM is backed up once a day, starting at the time; a VM that has not "
"started within 6 hours waits for the next day. Older backups of each VM "
"beyond the number kept are deleted; backups taken by hand are not."
msgstr "每台虚拟机每天从该时间开始备份一次;6 小时内未开始的虚拟机将等待第二天。每台虚拟机超出保留数量的旧备份会被删除;手动创建的备份不会被删除。"
"beyond the number kept are deleted, a chain of incremental backups once all "
"of it is beyond; backups taken by hand are not."
msgstr ""
"每台虚拟机每天从指定时间开始备份一次;6 "
"小时内未开始的虚拟机等待第二天。超出保留数量的较旧备份会被删除,增量备份链在整条链都超出时才删除;手动备份不会被删除。"
#: vmbackups/templates/vmbackups/restore.html:12
#, python-format

View file

@ -71,9 +71,10 @@ class PolicyForm(forms.ModelForm):
class Meta:
model = BackupPolicy
fields = ["name", "target", "compute", "instances", "time", "keep", "frozen", "enabled"]
fields = ["name", "target", "compute", "instances", "time", "keep", "full_every", "frozen", "enabled"]
labels = {"name": _("Name"), "target": _("Backup target"), "compute": _("Every VM of a compute"),
"instances": _("Or these VMs"), "time": _("Daily at"), "keep": _("Backups to keep of each VM"),
"full_every": _("A full backup every N backups"),
"frozen": _("Require frozen file systems"), "enabled": _("Enabled")}
widgets = {"time": forms.TimeInput(attrs={"type": "time"}, format="%H:%M"),
"instances": forms.SelectMultiple(attrs={"data-searchable": "1"})}
@ -83,8 +84,11 @@ class PolicyForm(forms.ModelForm):
self.fields["instances"].queryset = Instance.objects.filter(is_template=False).select_related("compute").order_by(
"name")
self.fields["instances"].label_from_instance = lambda vm: f"{vm.name} ({vm.compute.name})"
self.fields["keep"].validators.append(_min_one)
self.fields["keep"].widget.attrs["min"] = 1
for name in ("keep", "full_every"):
self.fields[name].validators.append(_min_one)
self.fields[name].widget.attrs["min"] = 1
self.fields["full_every"].help_text = _("1: every backup is full. Above 1, the backups between copy only what "
"changed (running VMs with qcow2 disks).")
def clean(self):
data = super().clean()

View file

@ -1 +1 @@
{% load i18n %}{% if backup.consistency == "offline" %}{% trans "Shut off" %}{% elif backup.consistency == "frozen" %}{% trans "Frozen" %}{% elif backup.consistency == "crash" %}{% trans "Crash-consistent" %}{% else %}–{% endif %}
{% load i18n %}{% if backup.consistency == "offline" %}{% trans "Shut off" %}{% elif backup.consistency == "frozen" %}{% trans "Frozen" %}{% elif backup.consistency == "crash" %}{% trans "Crash-consistent" %}{% else %}–{% endif %}{% if backup.parent_id %} <span class="badge text-bg-light border" title="{% trans 'Copies only what changed since the backup it builds on' %}">{% trans "Incremental" %}</span>{% endif %}

View file

@ -9,11 +9,12 @@
<div class="col-md-7">{% bootstrap_field form.instances %}</div>
</div>
<div class="row g-2">
<div class="col-6">{% blocktrans asvar zone_help %}Time zone: {{ time_zone }}{% endblocktrans %}{% bootstrap_field form.time help_text=zone_help %}</div>
<div class="col-6">{% bootstrap_field form.keep %}</div>
<div class="col-md-4">{% blocktrans asvar zone_help %}Time zone: {{ time_zone }}{% endblocktrans %}{% bootstrap_field form.time help_text=zone_help %}</div>
<div class="col-md-4">{% bootstrap_field form.keep %}</div>
<div class="col-md-4">{% bootstrap_field form.full_every %}</div>
</div>
{% bootstrap_field form.frozen %}
{% bootstrap_field form.enabled %}
<p class="small text-body-secondary">{% trans "Each VM is backed up once a day, starting at the time; a VM that has not started within 6 hours waits for the next day. Older backups of each VM beyond the number kept are deleted; backups taken by hand are not." %}</p>
<p class="small text-body-secondary">{% trans "Each VM is backed up once a day, starting at the time; a VM that has not started within 6 hours waits for the next day. Older backups of each VM beyond the number kept are deleted, a chain of incremental backups once all of it is beyond; backups taken by hand are not." %}</p>
<button type="submit" class="btn btn-primary">{% trans "Save" %}</button>
</form>

View file

@ -27,7 +27,8 @@ class PolicyPageTests(TestCase):
BackupTargetPool.objects.create(target=self.target, compute=self.c1, pool="b1", pool_uuid="u")
def post(self, **fields):
data = {"name": "nightly", "target": self.target.pk, "time": "02:00", "keep": "7", "enabled": "on", **fields}
data = {"name": "nightly", "target": self.target.pk, "time": "02:00", "keep": "7", "full_every": "1", "enabled": "on",
**fields}
return self.client.post(reverse("vmbackups:policies"), data)
def test_a_schedule_of_chosen_vms(self):
@ -57,9 +58,12 @@ class PolicyPageTests(TestCase):
self.assertContains(response, "has no storage pool on h2")
self.assertFalse(BackupPolicy.objects.exists())
def test_keep_at_least_one(self):
def test_keep_and_full_every_at_least_one(self):
self.assertEqual(self.post(instances=[self.vm1.pk], keep="0").status_code, 200)
self.assertEqual(self.post(instances=[self.vm1.pk], full_every="0").status_code, 200)
self.assertFalse(BackupPolicy.objects.exists())
self.post(instances=[self.vm1.pk], full_every="7")
self.assertEqual(BackupPolicy.objects.get().full_every, 7)
def schedule(self):
policy = BackupPolicy.objects.create(name="nightly", target=self.target, time=datetime.time(2), keep=7,
@ -74,7 +78,7 @@ class PolicyPageTests(TestCase):
url = reverse("vmbackups:policy", args=[policy.pk])
page = self.client.get(url)
self.assertContains(page, "The host was in maintenance")
self.client.post(url, {"name": "nightly", "target": self.target.pk, "time": "03:30", "keep": "3",
self.client.post(url, {"name": "nightly", "target": self.target.pk, "time": "03:30", "keep": "3", "full_every": "1",
"instances": [self.vm1.pk]})
policy.refresh_from_db()
self.assertEqual((policy.time, policy.keep, policy.enabled), (datetime.time(3, 30), 3, False))
@ -99,6 +103,11 @@ class PolicyPageTests(TestCase):
self.assertIn("nightly", row)
self.assertIn("Missing", row)
self.assertFalse(index.xpath("//a[contains(@href, '/restore/')]")) # a missing backup is not restored
self.assertNotIn("Incremental", row)
Backup.objects.create(target=self.target, instance=self.vm1, vm_uuid=self.vm1.uuid, vm_name="vm1",
compute_name="h1", state=Backup.READY, policy=policy, parent=Backup.objects.get())
index = lxml_html.fromstring(self.client.get(reverse("vmbackups:index")).content)
self.assertIn("Incremental", " ".join(index.xpath("//table[@id='backups']/tbody/tr/td//text()")))
def test_a_target_with_a_schedule_is_not_deleted(self):
self.schedule()