mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 01:16:10 +00:00
feat(vmbackups): a backup's file names begin with its VM's name
Someone looking at the target's directory could not tell whose backup a file was without opening its manifest. A new backup's files are named <vm>-<backup uuid>-<file> (the VM's name made safe for a file name, at most 64 characters). The prefix is kept on the row: backups made before keep their wvc-<uuid> names (migration 0007), and an import takes it from the manifest's file name. Manifests of either naming are found by their UUID suffix.
This commit is contained in:
parent
8e0a84a3bd
commit
5b05e76ebc
8 changed files with 81 additions and 33 deletions
|
|
@ -6,6 +6,7 @@ from django.db import models
|
|||
from computes.models import Compute
|
||||
from instances.models import Instance
|
||||
from operations.models import Operation
|
||||
from vrtManager.backup import backup_prefix
|
||||
|
||||
|
||||
class BackupTarget(models.Model):
|
||||
|
|
@ -112,6 +113,7 @@ class Backup(models.Model):
|
|||
checkpoint = models.CharField(max_length=64, blank=True) # the VM's checkpoint made with it
|
||||
# whose job made it: a VM owner's own backups count in their backup quota
|
||||
taken_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, related_name="+")
|
||||
prefix = models.CharField(max_length=128) # every file of the backup in the target begins with it and "-"
|
||||
|
||||
class Meta:
|
||||
ordering = ["-created_at"]
|
||||
|
|
@ -126,10 +128,10 @@ 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()
|
||||
|
||||
@property
|
||||
def prefix(self):
|
||||
"""Every file of the backup in the target is named from its UUID only."""
|
||||
return f"wvc-{self.uuid}"
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.prefix:
|
||||
self.prefix = backup_prefix(self.vm_name, self.uuid)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class BackupFile(models.Model):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue