mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix(vmbackups): seventh audit: files of a VM named after a backup, restore-over page
- A VM may be named "<another backup's prefix>-x": its backups' files then begin with that prefix too, and deleting the other backup removed them. Backup.owns() takes a file only when no other backup UUID follows the prefix; deletion and the storage pages' refusal use it. - The restore-over page failed with a server error when the VM's pool could not be read while naming the copies; it now says why.
This commit is contained in:
parent
5b05e76ebc
commit
348628f13d
6 changed files with 36 additions and 3 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
import uuid
|
||||
|
||||
from django.conf import settings
|
||||
|
|
@ -86,6 +87,9 @@ class BackupRun(models.Model):
|
|||
constraints = [models.UniqueConstraint(fields=["policy", "instance", "day"], name="one_run_per_day")]
|
||||
|
||||
|
||||
UUID_IN_NAME = re.compile(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")
|
||||
|
||||
|
||||
class Backup(models.Model):
|
||||
CREATING, READY, FAILED, DELETING, MISSING = "creating", "ready", "failed", "deleting", "missing"
|
||||
STATES = [(CREATING, "creating"), (READY, "ready"), (FAILED, "failed"), (DELETING, "deleting"), (MISSING, "missing")]
|
||||
|
|
@ -128,6 +132,11 @@ class Backup(models.Model):
|
|||
"""Whether a backup builds on this one: a failed one holds nothing."""
|
||||
return self.children.filter(state__in=self.LIVING).exists()
|
||||
|
||||
def owns(self, name):
|
||||
"""Whether the target's file name is one of this backup's: its prefix, then no other backup's UUID (a
|
||||
VM may be named "<this prefix>-x", and its backups' files begin with this prefix too)."""
|
||||
return name.startswith(self.prefix + "-") and not UUID_IN_NAME.search(name, len(self.prefix))
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.prefix:
|
||||
self.prefix = backup_prefix(self.vm_name, self.uuid)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue