Bỏ qua để đến nội dung
Playbook: backups and restore Set up backup destinations and scheduled backup jobs, run a backup now, list and verify snapshots, and restore (in place or onto another server) from an AI agent with the backup_* operations.

Playbook: backups and restore

Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.

Backups run on the box as archives (.tar.gz plus a manifest) that are pushed to a destination. They use dedicated operations, not jobs_create. That’s because a backup carries sealed destination credentials that the API injects itself.

Token: operate to create and run jobs. Restoring needs full + backups:restore with no server allowlist, since restore is a fleet-wide operation. Deletes need data:delete. Plan: local destinations on every plan; object storage (S3, R2, B2, rclone/Google Drive) from Plus (below it: 403 tier_limit). Server-to-server (peer) destinations are Pro+ and need the holder server online on agent 0.2.143 or newer: create with kind: "peer", config.peer_server_id = the holder; the API provisions an SFTP account on the holder in the same call. If the holder is older or offline you get 502 peer_provision_failed (400 unsupported_kind on an older control plane): do not retry, ask the user to update the holder’s agent (agent_update) or offer an object destination. The holder cannot back up to its own peer (use local). All sources share one account on a holder, so any of them can read or delete the others’ archives: suggest mode: "advanced" when the servers belong to different people, and tell the user to download each source server’s backup key (it lives only on that server). Each plan also caps the number of destinations and backup jobs.

  • backup_destinations_list lists destinations without their credentials. A local destination needs no credentials.
  • Adding one: backup_destinations_create {body: {kind: "local"|"object", label, provider?, config, cred_sealed?}} (full + webhooks:admin). Object-storage credentials must be sealed client-side to the servers’ public keys (backups_recipients). An agent should usually ask the user to add credentialed destinations in the dashboard (/backups) and then pick the new destination from the list.
  • MZPanel Cloud Backup (storage MZPanel provides, backup-100gb add-on, $3 / 100 GB, every plan): backups_cloud returns enabled, state (active | grace = add-on removed, read-only until graceUntil, then deleted), quotaBytes, usedBytes, destinationId (put it in destination_ids) and keyNotSaved (servers whose encryption key was never downloaded — tell the user: without the key those backups cannot be restored). Turning it on needs the owner in the dashboard (Backups → Destinations); a token cannot. A full space makes runs fail with “Cloud Backup is full” until the user adds storage or lowers retention.
  • Check it from a server: backup_destinations_test {id, body: {server_id}} (records the status) or backup_destinations_check {id, body: {server_id}}.

backup_jobs_create {id: <server UUID>, body}:

{
"name": "nightly-sites",
"kind": "full",
"target_kind": "site",
"targets": [{ "target_kind": "site", "name": "shop.example.com" },
{ "target_kind": "stack", "name": "shop" }],
"schedule": { "freq": "daily", "time": { "h": 2, "m": 30 }, "tz": "UTC" },
"destination_ids": ["<destination uuid>"],
"retention": { "keep": 14, "unit": "days" },
"encrypt": false,
"enabled": true
}
  • kind: full, database or files. target_kind: site, app, stack or server.
  • schedule.freq: hourly, daily, weekly, monthly or custom. Optional fields: everyHours, weekdays (0–6), monthdays (1–31), time {h, m}, cron and tz.
  • retention: {keep: 1–3650, unit: "days" | "copies"}.
  • encrypt: true seals each archive with a per-server passphrase. The user must keep that passphrase, and a token cannot read it.
  • include_image: true (app targets): each app archive also carries the app image, so an app built on its server from git or an upload restores on another server. Archives grow by the image size; a server without the free disk fails the run with image_no_space. Suggest it for apps built from source.

Edit with backup_jobs_update, and pause or resume with backup_jobs_toggle.

  • A saved job: backup_jobs_run {id: <server UUID>, jobId} answers {ok, started}. If the server is offline, the answer carries error.message: "Server is offline". Cancel with backup_jobs_cancel {id, jobId}.
  • One site, Docker app or stack, without a saved job: backups_run_once {id, body: {targetKind: "site"|"app"|"stack", target: <domain or name>, destinationId?, kind?}}. kind (full default, files, database) applies to sites only; includeImage: true (apps only, else 400) saves the app image into the archive. It defaults to the local destination and returns the snapshot id and, when the server is not busy with another backup, a job stream; confirm the result with backup_snapshots_list. A domain that is not a site on that server answers 404 not_found.

Watch progress with backup_jobs_list {id} (last run status) and jobs_list {id}.

  • backup_snapshots_list (add query: {server_id} to filter) lists what can be restored.
  • backup_snapshots_refresh {id} re-imports the catalog from the server’s destinations.
  • backup_snapshots_verify {id} checks that completed snapshots still exist where they were stored.
  • Clean-up (data:delete): backup_snapshots_delete {id} and backup_snapshots_clear_failed.

backup_snapshots_restore {id: <snapshot id>, body} needs full + backups:restore:

{ "scope": "full", "target_server_id": "<optional other server>", "target_site": "<optional other domain>" }
  • scope is required: full, database or files.
  • The operation is fleet-wide (the snapshot’s server comes from its stored row, not from the request), so a token with a server allowlist gets 403 fleet_wide. Use a token without an allowlist, even when you restore onto the same server.
  • With no target, the restore overwrites the original site, app or stack in place. Pass target_server_id and/or target_site to restore a copy somewhere else.
  • A site restore stages the files, shows a 503 “being restored” page, dumps the current database, imports, then swaps the files in; any failure rolls both back. On failure read failure.code in jobs_get: restore_snapshot_failed and restore_rolled_back mean the site runs as before (fix the cause, retry once); restore_rollback_failed means stop and tell the owner (the kept safety copies are named in jobs_output). Docker app/stack restores have no rollback.
  • A Docker app built from source restores on another server only from a snapshot whose image is set in backup_snapshots_list (taken with include_image); the image is loaded there first. Without it the job fails image_missing before touching anything: back the app up with includeImage: true on its own server first.
  • The answer is {job_id, status, stream_url, target_server_id}. Poll jobs_get {id: job_id}. If the target server is offline, you get 409.

Before restoring in place, take a fresh backup of the current state (step 3), so the restore can itself be undone.

After a run, backup_snapshots_list should show a new completed snapshot with a non-trivial size. After a restore, re-read the site, app or database and fetch the URL.