Expire scheduled archives with retained backup safeguards

This commit is contained in:
parkel committed 2026-11-21 15:08:48 +01:00
1 parent d088a487a3
commit cb8295dc38
10 files changed
+571 -14

No files matched your search

+45 -1
View File
@@ -11,6 +11,7 @@ from django.urls import reverse
from django.utils import timezone
from coulobre.account_backup_request import backup_archive
from coulobre.account_backup_retention import MAX_RETAINED_BACKUPS
from coulobre.account_restore_request import MAX_RESTORE_PATH_BYTES
from coulobre.database_node import (
DATABASE_SUFFIX_PATTERN,
@@ -180,8 +181,28 @@ class HostingAccount(models.Model):
customer = models.ForeignKey(
Customer, on_delete=models.PROTECT, null=True, blank=True
)
scheduled_backups_to_keep = models.PositiveSmallIntegerField(
null=True,
blank=True,
validators=[
MinValueValidator(1),
MaxValueValidator(MAX_RETAINED_BACKUPS),
],
)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
constraints = [
models.CheckConstraint(
condition=models.Q(scheduled_backups_to_keep__isnull=True)
| models.Q(
scheduled_backups_to_keep__gte=1,
scheduled_backups_to_keep__lte=MAX_RETAINED_BACKUPS,
),
name="hosting_account_valid_backup_retention",
)
]
def __str__(self):
return str(self.primary_domain)
@@ -447,6 +468,9 @@ class AccountBackupJob(ProvisioningJob):
)
manifest = models.JSONField()
scheduled_for = models.DateTimeField(null=True, blank=True)
archive_bytes = models.PositiveBigIntegerField(null=True, blank=True)
retention_protected = models.BooleanField(default=False)
expired_at = models.DateTimeField(null=True, blank=True)
class Meta:
indexes = [models.Index(fields=("finished_at", "requested_at"))]
@@ -459,13 +483,33 @@ class AccountBackupJob(ProvisioningJob):
def includes_mailboxes(self):
return "mailboxes" in self.manifest
@property
def archive_is_restorable(self):
if self.state != "configured" or self.expired_at is not None:
return False
expiration = getattr(self, "expiration", None)
return expiration is None or expiration.finished_at is not None
def can_restore_website(self, site):
return (
self.state == "configured"
self.archive_is_restorable
and self.manifest.get("website") == site.manifest()
)
class AccountBackupExpiration(ProvisioningJob):
backup = models.OneToOneField(
AccountBackupJob, on_delete=models.CASCADE, related_name="expiration"
)
keeper_ids = models.JSONField()
class Meta:
indexes = [models.Index(fields=("finished_at", "requested_at"))]
permissions = [
("manage_backup_retention", "Can manage account backup retention"),
]
class WebsiteRestoreJob(ProvisioningJob):
backup = models.ForeignKey(
AccountBackupJob,