diff --git a/deploy/systemd/coulobre-account-offsite@.service b/deploy/systemd/coulobre-account-offsite@.service
index a5dbb8a..317b670 100644
--- a/deploy/systemd/coulobre-account-offsite@.service
+++ b/deploy/systemd/coulobre-account-offsite@.service
@@ -20,4 +20,5 @@ PrivateTmp=true
PrivateDevices=true
ProtectHome=true
ProtectSystem=strict
+ReadWritePaths=-/var/lib/coulobre/account-backups
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
diff --git a/docs/deployment.md b/docs/deployment.md
index d2f1f48..1f8aecb 100644
--- a/docs/deployment.md
+++ b/docs/deployment.md
@@ -1982,7 +1982,7 @@ worker delivery from recreating an expired archive.
#### Copy scheduled account backups off-site
-Coulobre can send scheduled archives to an encrypted restic repository over
+Coulobre can send account archives to an encrypted restic repository over
SFTP. On the backup node, install restic and OpenSSH and create a directory
for each destination. This example uses the destination ID `vault`.
[Restic SFTP repository setup](https://restic.readthedocs.io/en/stable/030_preparing_a_new_repo.html#sftp)
@@ -2028,6 +2028,15 @@ For manual installations or additional destinations, set
`/etc/coulobre/panel.env`. This setting contains IDs and labels. Each ID
maps to a directory under `/etc/coulobre/offsite` on the backup node.
+Local tooling can also publish an ID-to-label JSON object in
+`/etc/coulobre-offsite-destinations.json`. Use a root-owned regular file
+with mode `0644` and replace it atomically. Add an ID only after preparing
+and verifying its root-only profile. The catalog contains no hostnames,
+repository paths or credentials. Existing IDs from `panel.env` take
+precedence. The panel and workers discover updates without a restart once
+the off-site services are installed and running. Never repoint an existing
+ID to a different repository.
+
```sh
sudo groupadd --system coulobre-offsite-requests
sudo useradd --system --user-group --no-create-home --home-dir /nonexistent \
@@ -2041,16 +2050,18 @@ sudo systemctl enable --now coulobre-offsite-worker.service
sudo systemctl restart coulobre-panel coulobre-worker coulobre-beat
```
-Choose the destination in **Backup schedule**. The choice applies to future
-scheduled backups. The archive history shows transfer status. A copy becomes
+Choose the destination in **Backup schedule** for future scheduled backups,
+or next to **Create backup** to send a one-off copy. Both use the same local
+archive and transfer queue. The archive history shows transfer status. A copy becomes
**Verified** after the worker reads it back from restic and verifies its
size and SHA-256 checksum. Allow time and bandwidth for both the upload
and verification within the 30-minute transfer deadline. An interrupted
transfer reuses an existing snapshot with the same backup ID and verifies
it again. The worker makes up to five attempts before requiring a manual
retry. Operators with **Can change offsite backup transfer** can retry a
-failed copy from the archive history. Add `offsite-backups` to the local
-service health list to monitor the worker.
+failed copy from the archive history or include a destination in a manual
+backup. Add `offsite-backups` to the local service health list to monitor the
+worker.
Archives awaiting verification stay on the backup node and do not count
toward the eligible local retention set. Once verified, they follow the
@@ -2059,10 +2070,20 @@ retention in restic on the storage side. Assign a new destination ID when
switching repositories. Keep the original profile and recovery credentials
for as long as you retain copies in that repository.
-To recover a copy, take its destination ID, account ID, and backup ID from
-the archive history. Run the recovery command on a node with the
-destination profile. It looks up the snapshot by backup ID and verifies
-the checksum in its authenticated metadata before creating the output file.
+On the backup archive list, **Recover local archive** downloads a verified
+copy and checks it against the snapshot ID and SHA-256 recorded by the panel.
+The recovered copy appears as a separate local archive. It does not change
+live content, revive expired archives or inherit the source's retention
+schedule. Use the existing website, database or mailbox restore actions on
+the recovered archive, subject to the same restore permissions and target
+checks. On a manual upgrade, update the installed off-site socket service
+unit from the release along with the panel, so recovery can write to the
+local account backup directory.
+
+To recover without the panel, take the destination ID, account ID and backup
+ID from the archive history. On a node with the destination profile, the
+recovery command looks up the snapshot by backup ID and verifies the checksum
+in its authenticated metadata before creating the output file.
```sh
sudo install -d -m 0700 /srv/coulobre-recovery
diff --git a/src/coulobre/hosting/account_backup_forms.py b/src/coulobre/hosting/account_backup_forms.py
index 362a929..6e5c0dc 100644
--- a/src/coulobre/hosting/account_backup_forms.py
+++ b/src/coulobre/hosting/account_backup_forms.py
@@ -1,7 +1,6 @@
from uuid import uuid4
from django import forms
-from django.conf import settings
from django.core.exceptions import ValidationError
from coulobre.account_backup_retention import MAX_RETAINED_BACKUPS
@@ -13,6 +12,7 @@ from coulobre.database_node import DatabaseSpec
from .installation_features import panel_feature_allowed
from .models import AccountBackupSchedule
+from .offsite_destinations import offsite_destinations
SCHEDULE_FIELDS = (
"enabled",
@@ -51,7 +51,7 @@ class AccountBackupScheduleForm(forms.Form):
if not allow_mail and not self.initial.get("include_mailboxes"):
del self.fields["include_mailboxes"]
destinations = (
- settings.OFFSITE_BACKUP_DESTINATIONS
+ offsite_destinations()
if panel_feature_allowed("OFFSITE_BACKUP_DESTINATIONS")
else {}
)
diff --git a/src/coulobre/hosting/account_backups.py b/src/coulobre/hosting/account_backups.py
index e8525c9..c38cb5d 100644
--- a/src/coulobre/hosting/account_backups.py
+++ b/src/coulobre/hosting/account_backups.py
@@ -15,6 +15,7 @@ from .models import (
HostingMailbox,
OffsiteBackupTransfer,
)
+from .offsite_destinations import offsite_destinations
from .resource_requests import lock_hosting_account, require_open_account
@@ -68,9 +69,15 @@ def queue_account_backup(
include_website=True,
include_databases=True,
database_suffix="",
+ offsite_destination="",
):
account = lock_hosting_account(account_id, customer_id=customer_id)
require_open_account(account)
+ if offsite_destination and (
+ customer_id is not None
+ or offsite_destination not in offsite_destinations()
+ ):
+ raise ValidationError("Choose an available off-site destination.")
if database_suffix and not (
customer_id is not None
and include_databases
@@ -92,6 +99,7 @@ def queue_account_backup(
include_databases=include_databases,
export_customer_id=customer_id,
database_suffix=database_suffix,
+ offsite_destination=offsite_destination,
)
@@ -121,7 +129,7 @@ def _enqueue_backup(
export_customer_id=export_customer_id,
export_database_suffix=database_suffix,
)
- if scheduled_for is not None and offsite_destination:
+ if offsite_destination:
OffsiteBackupTransfer.objects.create(
backup=job, destination=offsite_destination
)
@@ -157,7 +165,7 @@ def save_backup_schedule(account_id, *, can_manage_mail, schedule_fields):
if (
schedule_fields["enabled"]
and destination
- and destination not in settings.OFFSITE_BACKUP_DESTINATIONS
+ and destination not in offsite_destinations()
):
raise ValidationError("Choose an available off-site destination.")
diff --git a/src/coulobre/hosting/installation_features.py b/src/coulobre/hosting/installation_features.py
index 3cbe13e..fea426c 100644
--- a/src/coulobre/hosting/installation_features.py
+++ b/src/coulobre/hosting/installation_features.py
@@ -9,6 +9,7 @@ from coulobre.linked_updates import UNIT_DIR
from .dns_defaults import zone_defaults
from .models import PanelFeaturePolicy
+from .offsite_destinations import offsite_destinations
DEPLOYMENT_GUIDE = (
"https://code.hosting.hippogrief.nl/hippogrief/coulobre/"
@@ -32,6 +33,8 @@ class Feature:
@property
def configured(self):
+ if self.setting == "OFFSITE_BACKUP_DESTINATIONS":
+ return bool(offsite_destinations())
if self.setting == "DEFAULT_DNS_ZONES":
defaults = zone_defaults()
return bool(
@@ -224,7 +227,12 @@ current_policy = ContextVar("current_feature_policy", default=None)
def panel_feature_allowed(setting):
- if not getattr(settings, setting):
+ configured = (
+ offsite_destinations()
+ if setting == "OFFSITE_BACKUP_DESTINATIONS"
+ else getattr(settings, setting)
+ )
+ if not configured:
return False
return not panel_feature_paused(setting)
diff --git a/src/coulobre/hosting/installation_views.py b/src/coulobre/hosting/installation_views.py
index 8ec801b..dec3948 100644
--- a/src/coulobre/hosting/installation_views.py
+++ b/src/coulobre/hosting/installation_views.py
@@ -32,6 +32,7 @@ from .models import (
PanelFeaturePolicy,
WebsiteDomain,
)
+from .offsite_destinations import offsite_destinations
from .operator_tools import package_operation_pending, queue_operator_request
from .update_views import inspect_linked_nodes
@@ -55,10 +56,15 @@ TOOL_SETTINGS = {
def managed_tool_available(tool):
_, setting, prerequisite = TOOL_FEATURES[tool]
+ configured = (
+ offsite_destinations()
+ if tool == "offsite"
+ else getattr(settings, setting)
+ )
return (
Path(SOCKET).is_socket()
and PACKAGE_ASSETS.is_dir()
- and not getattr(settings, setting)
+ and not configured
and getattr(settings, prerequisite)
)
diff --git a/src/coulobre/hosting/migrations/0093_offsite_backup_recovery.py b/src/coulobre/hosting/migrations/0093_offsite_backup_recovery.py
new file mode 100644
index 0000000..55f90c1
--- /dev/null
+++ b/src/coulobre/hosting/migrations/0093_offsite_backup_recovery.py
@@ -0,0 +1,72 @@
+# Generated by Django 5.2.19 on 2026-12-03 20:08
+
+import uuid
+
+import django.db.models.deletion
+import django.utils.timezone
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("hosting", "0092_independent_website_starter_page"),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name="OffsiteBackupRecovery",
+ fields=[
+ (
+ "id",
+ models.BigAutoField(
+ auto_created=True,
+ primary_key=True,
+ serialize=False,
+ verbose_name="ID",
+ ),
+ ),
+ (
+ "requested_at",
+ models.DateTimeField(default=django.utils.timezone.now),
+ ),
+ (
+ "last_dispatched_at",
+ models.DateTimeField(blank=True, null=True),
+ ),
+ ("started_at", models.DateTimeField(blank=True, null=True)),
+ ("finished_at", models.DateTimeField(blank=True, null=True)),
+ ("problem", models.TextField(blank=True)),
+ (
+ "recovered_id",
+ models.UUIDField(
+ default=uuid.uuid4, editable=False, unique=True
+ ),
+ ),
+ (
+ "recovered_backup",
+ models.OneToOneField(
+ null=True,
+ on_delete=django.db.models.deletion.SET_NULL,
+ related_name="offsite_recovery",
+ to="hosting.accountbackupjob",
+ ),
+ ),
+ (
+ "transfer",
+ models.OneToOneField(
+ on_delete=django.db.models.deletion.CASCADE,
+ related_name="recovery",
+ to="hosting.offsitebackuptransfer",
+ ),
+ ),
+ ],
+ options={
+ "indexes": [
+ models.Index(
+ fields=["finished_at", "requested_at"],
+ name="hosting_off_finishe_238a8b_idx",
+ )
+ ],
+ },
+ ),
+ ]
diff --git a/src/coulobre/hosting/models.py b/src/coulobre/hosting/models.py
index 7f1f597..ff8c53b 100644
--- a/src/coulobre/hosting/models.py
+++ b/src/coulobre/hosting/models.py
@@ -48,6 +48,7 @@ from coulobre.web_node import MAX_STORAGE_LIMIT_MIB, WebSite
from coulobre.website_job import MAX_JOB_COMMAND_LENGTH
from .fields import DomainNameField
+from .offsite_destinations import offsite_destinations
class Reseller(models.Model):
@@ -1467,7 +1468,7 @@ class OffsiteBackupTransfer(ProvisioningJob):
return "Waiting for local archive"
if self.backup.problem:
return "Local backup failed"
- if self.destination not in settings.OFFSITE_BACKUP_DESTINATIONS:
+ if not self.destination_available:
return "Destination unavailable"
if self.finished_at is not None:
return "Failed"
@@ -1477,11 +1478,33 @@ class OffsiteBackupTransfer(ProvisioningJob):
return "Retry scheduled"
return "Queued"
+ @property
+ def destination_available(self):
+ return self.destination in offsite_destinations()
+
@property
def label(self):
- return settings.OFFSITE_BACKUP_DESTINATIONS.get(
- self.destination, self.destination
- )
+ return offsite_destinations().get(self.destination, self.destination)
+
+
+class OffsiteBackupRecovery(ProvisioningJob):
+ transfer = models.OneToOneField(
+ OffsiteBackupTransfer,
+ on_delete=models.CASCADE,
+ related_name="recovery",
+ )
+ recovered_id = models.UUIDField(
+ default=uuid.uuid4, unique=True, editable=False
+ )
+ recovered_backup = models.OneToOneField(
+ AccountBackupJob,
+ on_delete=models.SET_NULL,
+ null=True,
+ related_name="offsite_recovery",
+ )
+
+ class Meta:
+ indexes = [models.Index(fields=("finished_at", "requested_at"))]
class AccountBackupExpiration(ProvisioningJob):
diff --git a/src/coulobre/hosting/offsite_backups.py b/src/coulobre/hosting/offsite_backups.py
index 9d0eb6b..efc3ca8 100644
--- a/src/coulobre/hosting/offsite_backups.py
+++ b/src/coulobre/hosting/offsite_backups.py
@@ -1,6 +1,5 @@
from datetime import timedelta
-from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import transaction
from django.db.models import F, Q
@@ -11,11 +10,17 @@ from coulobre.offsite_backup import (
OFFSITE_SOCKET,
TRANSFER_TIMEOUT_SECONDS,
OffsiteBackupRequest,
+ OffsiteRecoveryRequest,
)
-from .models import OffsiteBackupTransfer
+from .models import (
+ AccountBackupJob,
+ OffsiteBackupRecovery,
+ OffsiteBackupTransfer,
+)
from .node_client import apply_on_local_node
from .notifications import notify_backup
+from .offsite_destinations import offsite_destinations
OFFSITE_BACKUP_QUEUE = "coulobre-offsite-backups"
OFFSITE_BACKUP_LEASE = timedelta(seconds=TRANSFER_TIMEOUT_SECONDS + 60)
@@ -28,7 +33,7 @@ TRANSFER_PROBLEM = (
def transfer_scope(now):
return {
"next_attempt_at__lte": now,
- "destination__in": settings.OFFSITE_BACKUP_DESTINATIONS,
+ "destination__in": offsite_destinations(),
"backup__finished_at__isnull": False,
"backup__problem": "",
"backup__expired_at__isnull": True,
@@ -130,7 +135,7 @@ def run_offsite_transfer(job_id):
@transaction.atomic
def retry_offsite_transfer(transfer):
- if transfer.destination not in settings.OFFSITE_BACKUP_DESTINATIONS:
+ if transfer.destination not in offsite_destinations():
raise ValidationError(
"Configure the original off-site destination before retrying."
)
@@ -144,3 +149,70 @@ def retry_offsite_transfer(transfer):
next_attempt_at=timezone.now(),
):
raise ValidationError("Only failed off-site transfers can be retried.")
+
+
+@transaction.atomic
+def queue_offsite_recovery(transfer):
+ transfer = OffsiteBackupTransfer.objects.select_for_update().get(
+ pk=transfer.pk
+ )
+ if (
+ transfer.verified_at is None
+ or transfer.destination not in offsite_destinations()
+ ):
+ raise ValidationError("Choose an available, verified off-site copy.")
+ job, created = OffsiteBackupRecovery.objects.get_or_create(
+ transfer=transfer
+ )
+ if not created and job.problem:
+ OffsiteBackupRecovery.objects.requeue(
+ OffsiteBackupRecovery.objects.filter(pk=job.pk).exclude(problem="")
+ )
+
+
+def recover_verified_backup(job):
+ transfer = job.transfer
+ source = transfer.backup
+ if (
+ transfer.verified_at is None
+ or transfer.destination not in offsite_destinations()
+ ):
+ raise ValueError("The verified off-site copy is unavailable.")
+ request = OffsiteRecoveryRequest(
+ OffsiteBackupRequest(
+ source.account_id, source.backup_id, transfer.destination
+ ),
+ job.recovered_id,
+ transfer.snapshot,
+ transfer.sha256,
+ source.archive_bytes,
+ )
+ reply = apply_on_local_node(
+ request,
+ OFFSITE_SOCKET,
+ "off-site backup node",
+ "archive recovery",
+ timeout=TRANSFER_TIMEOUT_SECONDS + 20,
+ )
+ size = reply.get("archive_bytes")
+ if (
+ type(size) is not int
+ or not 1 <= size < 2**63
+ or (source.archive_bytes is not None and size != source.archive_bytes)
+ ):
+ raise ValueError("The off-site node returned an invalid archive size.")
+ archive, _ = AccountBackupJob.objects.get_or_create(
+ backup_id=job.recovered_id,
+ defaults={
+ "account": source.account,
+ "manifest": source.manifest,
+ "archive_bytes": size,
+ "finished_at": timezone.now(),
+ },
+ )
+ if (
+ archive.account_id != source.account_id
+ or archive.manifest != source.manifest
+ ):
+ raise ValueError("The recovered archive does not match the backup.")
+ return {"recovered_backup_id": archive.pk}
diff --git a/src/coulobre/hosting/offsite_destinations.py b/src/coulobre/hosting/offsite_destinations.py
new file mode 100644
index 0000000..b0dc219
--- /dev/null
+++ b/src/coulobre/hosting/offsite_destinations.py
@@ -0,0 +1,39 @@
+"""Discover local off-site profiles without reading credentials."""
+
+import json
+import os
+import stat
+from pathlib import Path
+
+from django.conf import settings
+
+from coulobre.offsite_backup import destination_labels
+
+CATALOG = Path("/etc/coulobre-offsite-destinations.json")
+MAX_CATALOG_BYTES = 16 * 1024
+
+
+def catalog_labels():
+ try:
+ descriptor = os.open(
+ CATALOG, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK
+ )
+ with os.fdopen(descriptor, "rb") as stream:
+ info = os.fstat(stream.fileno())
+ if (
+ not stat.S_ISREG(info.st_mode)
+ or info.st_uid != 0
+ or info.st_mode & 0o022
+ ):
+ return {}
+ content = stream.read(MAX_CATALOG_BYTES + 1)
+ if len(content) <= MAX_CATALOG_BYTES:
+ return destination_labels(json.loads(content))
+ except (OSError, ValueError, RecursionError):
+ pass
+ return {}
+
+
+def offsite_destinations():
+ # Never rebind or relabel an existing statically configured ID.
+ return catalog_labels() | settings.OFFSITE_BACKUP_DESTINATIONS
diff --git a/src/coulobre/hosting/tasks.py b/src/coulobre/hosting/tasks.py
index a5c7850..10c9d38 100644
--- a/src/coulobre/hosting/tasks.py
+++ b/src/coulobre/hosting/tasks.py
@@ -60,6 +60,7 @@ from .models import (
MailFilterCheck,
MailRoutingPublication,
MailVacationPublication,
+ OffsiteBackupRecovery,
OffsiteBackupTransfer,
SignInWindow,
SitePhpSettings,
@@ -112,9 +113,11 @@ from .offsite_backups import (
OFFSITE_BACKUP_LEASE,
OFFSITE_BACKUP_QUEUE,
finish_interrupted_transfers,
+ recover_verified_backup,
run_offsite_transfer,
transfer_scope,
)
+from .offsite_destinations import offsite_destinations
from .password_reset import send_customer_reset_email
from .php_settings import plan_php_versions
from .resource_requests import lock_hosting_account
@@ -500,7 +503,7 @@ def plan_account_backup_expirations():
@shared_task
def dispatch_offsite_backups():
- if settings.LOCAL_ACCOUNT_BACKUPS and settings.OFFSITE_BACKUP_DESTINATIONS:
+ if settings.LOCAL_ACCOUNT_BACKUPS and offsite_destinations():
now = timezone.now()
finish_interrupted_transfers(now)
dispatch_provisioning_jobs(
@@ -511,14 +514,32 @@ def dispatch_offsite_backups():
attempts__lt=MAX_OFFSITE_ATTEMPTS,
**transfer_scope(now),
)
+ dispatch_provisioning_jobs(
+ OffsiteBackupRecovery,
+ recover_offsite_backup,
+ OFFSITE_BACKUP_QUEUE,
+ lease=OFFSITE_BACKUP_LEASE,
+ )
@shared_task(acks_late=True, reject_on_worker_lost=True)
def transfer_offsite_backup(job_id):
- if settings.LOCAL_ACCOUNT_BACKUPS and settings.OFFSITE_BACKUP_DESTINATIONS:
+ if settings.LOCAL_ACCOUNT_BACKUPS and offsite_destinations():
run_offsite_transfer(job_id)
+@shared_task(acks_late=True, reject_on_worker_lost=True)
+def recover_offsite_backup(job_id):
+ if settings.LOCAL_ACCOUNT_BACKUPS:
+ run_provisioning_job(
+ OffsiteBackupRecovery.objects.select_related("transfer__backup"),
+ job_id,
+ recover_verified_backup,
+ "The backup node did not confirm recovery. You can retry.",
+ lease=OFFSITE_BACKUP_LEASE,
+ )
+
+
def dispatch_provisioning_jobs(
model, task, queue, *, lease=REDISPATCH_AFTER, condition=None, **scope
):
diff --git a/src/coulobre/hosting/templates/hosting/account_backup_archive_table.html b/src/coulobre/hosting/templates/hosting/account_backup_archive_table.html
index f0d415e..c361538 100644
--- a/src/coulobre/hosting/templates/hosting/account_backup_archive_table.html
+++ b/src/coulobre/hosting/templates/hosting/account_backup_archive_table.html
@@ -11,6 +11,8 @@