mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
feat(vmbackups): VM owners back up and restore their VMs within a quota
A permission 'Can back up instances' lets a user back up the VMs they may change into targets open to VM owners, restore those backups over the VM or as a new VM, and delete the backups they took by hand. Each job checks the rights at admission and again when it runs. - A backup quota (GiB, in the user's quota) counts the owner's own backups: a backup being made holds its estimate, what its disks and the files below them hold. An owner's backups run one at a time, so each run's check sees the others. - An owner restores as a new VM on the VM's compute, into its first disk's pool, within the VM quota; the job counts in it until its VM is recorded, as a clone does. - An owner's restore over the VM removes the disks it ran from once the switch is done, unless another VM uses them: the owner cannot remove them. - Recovery never begins a deletion the job had not begun. Superusers keep everything they had.
This commit is contained in:
parent
1b0a54e3d1
commit
db4cbf806a
22 changed files with 1155 additions and 520 deletions
|
|
@ -14,6 +14,7 @@ class BackupTarget(models.Model):
|
|||
name = models.CharField(max_length=64, unique=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
checked_at = models.DateTimeField(null=True) # its last target check that ended
|
||||
owners = models.BooleanField(default=False) # VM owners with the backup permission may use it
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
@ -87,6 +88,7 @@ class BackupRun(models.Model):
|
|||
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")]
|
||||
LIVING = (CREATING, READY, MISSING, DELETING) # its files are or will be in the target
|
||||
OFFLINE, FROZEN, CRASH = "offline", "frozen", "crash"
|
||||
CONSISTENCIES = [(OFFLINE, "offline"), (FROZEN, "frozen"), (CRASH, "crash-consistent")]
|
||||
|
||||
|
|
@ -108,13 +110,15 @@ class Backup(models.Model):
|
|||
# an incremental backup's base; its disk files have the parent's as backing files
|
||||
parent = models.ForeignKey("self", on_delete=models.SET_NULL, null=True, related_name="children")
|
||||
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="+")
|
||||
|
||||
class Meta:
|
||||
ordering = ["-created_at"]
|
||||
|
||||
def depended_on(self):
|
||||
"""Whether a backup builds on this one: a failed one holds nothing."""
|
||||
return self.children.filter(state__in=(self.CREATING, self.READY, self.MISSING, self.DELETING)).exists()
|
||||
return self.children.filter(state__in=self.LIVING).exists()
|
||||
|
||||
@property
|
||||
def prefix(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue