carlos / platform Public

cli: carlos instances backups, the page's backups facts (#898)

The backups door's answer as label/value lines mirroring the instance
page's Backups section: the three tile rows when the copy's newest point
is known, Database and Files on disk with their chips, the one reason
line, and the two db pull commands under their intros. --json prints the
door's body verbatim. No --instance picks the app's only instance
(resolveDBInstance); a refusal, 429 included, is apiErrorFromBody's.

The strings both surfaces show move to a new leaf, internal/backupswords,
which the console's backupsCopy and the CLI read; the copy record's file
entries follow them, and backups.cli.heading leaves pending.

Parity row instances-backups (both), cli.tsv and docs/parity.md
regenerated; docs/site/cli.md gets a heading and example only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev a106e8affe71addbcec768bb401ba2360aa7ed98 parent d070fb1
11 files changed, +643 −51
  • approved_member_backups_copy_test.go +1 −1
  • cli.go +1 −0
  • docs/parity.md +3 −2
  • docs/site/cli.md +6 −0
  • docs/superpowers/plans/member-backups-slice1-copy.json +24 −24
  • instances_backups.go +229 −0
  • instances_backups_test.go +308 −0
  • internal/backupswords/words.go +41 −0
  • internal/console/instancecopy.go +28 −24
  • parity/cli.tsv +1 −0
  • parity/parity.tsv +1 −0
diff --git a/approved_member_backups_copy_test.go b/approved_member_backups_copy_test.go
index 06ae4ad8f..c56582c44 100644
--- a/approved_member_backups_copy_test.go
+++ b/approved_member_backups_copy_test.go
@@ -29,6 +29,7 @@ var memberBackupsCopyIDs = []string{
"backups.why.demo", "backups.why.pooled", "backups.why.fleet",
"backups.why.otherregion", "backups.why.nothingyet",
"backups.cli.summary", "backups.cli.latest", "backups.cli.at",
+ "backups.cli.heading",
}
// memberBackupsPendingIDs are approved entries no file holds yet, each
@@ -41,7 +42,6 @@ var memberBackupsPendingIDs = map[string]string{
"backups.ready": "slice 1b",
"backups.ready.note": "slice 1b",
"backups.toolarge": "slice 1b",
- "backups.cli.heading": "slice 1 task 5",
}
// Every applied member backups string is present, byte for byte, in the
diff --git a/cli.go b/cli.go
index b92e3e5de..13e422847 100644
--- a/cli.go
+++ b/cli.go
@@ -588,6 +588,7 @@ func instancesCommand() *clireg.Node {
raw("create", cust, runInstancesCreate),
instancesImportCommand(),
raw("list", cust, runInstancesList),
+ raw("backups", cust, runInstancesBackups),
raw("delete", cust, runInstancesDelete),
instancesDoorKeyCommand(),
raw("set", cust, runInstancesSet),
diff --git a/docs/parity.md b/docs/parity.md
index 974105242..f533c0e56 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -10,12 +10,12 @@ CLI rows are checked against the command registry (`parity/cli.tsv`).
| Status | Rows |
|---|---:|
-| both | 43 |
+| both | 44 |
| partial | 9 |
| gap | 63 |
| cli-only | 15 |
| console-only | 17 |
-| Total | 147 |
+| Total | 148 |
## account
@@ -155,6 +155,7 @@ CLI rows are checked against the command registry (`parity/cli.tsv`).
| instances-updates | both | `instances set [--updates,--major,--pin]` | `POST /a/{sqid}/apps/{app}/instances/{host}/updates` | | |
| instances-update | both | `instances update` | `POST /a/{sqid}/apps/{app}/instances/{host}/updates/install` | | |
| instances-retry | both | `instances retry` | `POST /a/{sqid}/apps/{app}/instances/{host}/retry` | | |
+| instances-backups | both | `instances backups` | `GET /a/{sqid}/apps/{app}/instances/{host}` | | |
| steering | gap | `steering` | | [wp-instances](#wp-instances) | |
| routes | partial | `routes` | `GET /a/{sqid}/apps/{app}/instances`<br>`GET /a/{sqid}/apps/{app}/settings/{section}` | | The console shows host and channel but no environment or replication column. |
| restart | partial | `restart` | `POST /a/{sqid}/apps/{app}/restart`<br>`POST /a/{sqid}/apps/{app}/instances/{host}/restart` | | The console has no environment scope and no dry-run list. |
diff --git a/docs/site/cli.md b/docs/site/cli.md
index 4679c8fe7..0e33fb9f4 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -1345,6 +1345,12 @@ Turns page caching on or off for one instance. `off` throws away the pages it ke
carlos instances set-pages --app shop a.shop.example.com off
```
+### carlos instances backups
+
+```sh
+carlos instances backups --app shop --instance a.shop.example.com
+```
+
### carlos sidecars
A sidecar is a member that nothing can dial: a process the platform runs for
diff --git a/docs/superpowers/plans/member-backups-slice1-copy.json b/docs/superpowers/plans/member-backups-slice1-copy.json
index 4b8448f48..9b7180de4 100644
--- a/docs/superpowers/plans/member-backups-slice1-copy.json
+++ b/docs/superpowers/plans/member-backups-slice1-copy.json
@@ -5,36 +5,36 @@
"entries": [
{"id": "backups.heading", "file": "internal/console/instancecopy.go", "text": "Backups"},
{"id": "backups.download", "file": "internal/console/instancecopy.go", "text": "Download a copy", "pending": "slice 1b"},
- {"id": "backups.saved.label", "file": "internal/console/instancecopy.go", "text": "Last change saved"},
- {"id": "backups.saved.today", "file": "internal/console/instancecopy.go", "text": "today"},
- {"id": "backups.history.label", "file": "internal/console/instancecopy.go", "text": "Go back as far as"},
- {"id": "backups.history.detail", "file": "internal/console/instancecopy.go", "text": "about 7 days of history"},
- {"id": "backups.test.label", "file": "internal/console/instancecopy.go", "text": "Restore test"},
- {"id": "backups.test.none", "file": "internal/console/instancecopy.go", "text": "not shown yet"},
+ {"id": "backups.saved.label", "file": "internal/backupswords/words.go", "text": "Last change saved"},
+ {"id": "backups.saved.today", "file": "internal/backupswords/words.go", "text": "today"},
+ {"id": "backups.history.label", "file": "internal/backupswords/words.go", "text": "Go back as far as"},
+ {"id": "backups.history.detail", "file": "internal/backupswords/words.go", "text": "about 7 days of history"},
+ {"id": "backups.test.label", "file": "internal/backupswords/words.go", "text": "Restore test"},
+ {"id": "backups.test.none", "file": "internal/backupswords/words.go", "text": "not shown yet"},
{"id": "backups.keep.heading", "file": "internal/console/instancecopy.go", "text": "What we keep"},
- {"id": "backups.keep.db", "file": "internal/console/instancecopy.go", "text": "Database"},
- {"id": "backups.keep.files", "file": "internal/console/instancecopy.go", "text": "Files on disk"},
- {"id": "backups.chip.copied", "file": "internal/console/instancecopy.go", "text": "Copied"},
- {"id": "backups.chip.notcopied", "file": "internal/console/instancecopy.go", "text": "Not copied"},
- {"id": "backups.chip.notshown", "file": "internal/console/instancecopy.go", "text": "Not shown here"},
- {"id": "backups.chip.nothingyet", "file": "internal/console/instancecopy.go", "text": "Nothing yet"},
- {"id": "backups.chip.unavailable", "file": "internal/console/instancecopy.go", "text": "Can't read now"},
+ {"id": "backups.keep.db", "file": "internal/backupswords/words.go", "text": "Database"},
+ {"id": "backups.keep.files", "file": "internal/backupswords/words.go", "text": "Files on disk"},
+ {"id": "backups.chip.copied", "file": "internal/backupswords/words.go", "text": "Copied"},
+ {"id": "backups.chip.notcopied", "file": "internal/backupswords/words.go", "text": "Not copied"},
+ {"id": "backups.chip.notshown", "file": "internal/backupswords/words.go", "text": "Not shown here"},
+ {"id": "backups.chip.nothingyet", "file": "internal/backupswords/words.go", "text": "Nothing yet"},
+ {"id": "backups.chip.unavailable", "file": "internal/backupswords/words.go", "text": "Can't read now"},
{"id": "backups.preparing", "file": "internal/console/instancecopy.go", "text": "Preparing your copy", "pending": "slice 1b"},
{"id": "backups.preparing.note", "file": "internal/console/instancecopy.go", "text": "Usually a minute or two. We'll email you when it's ready.", "pending": "slice 1b"},
{"id": "backups.ready", "file": "internal/console/instancecopy.go", "text": "Download {file} ({size})", "pending": "slice 1b"},
{"id": "backups.ready.note", "file": "internal/console/instancecopy.go", "text": "Ready until {time} tomorrow.", "pending": "slice 1b"},
{"id": "backups.toolarge", "file": "internal/console/instancecopy.go", "text": "Too large to download here. Use the command line below.", "pending": "slice 1b"},
- {"id": "backups.why.nosleep", "file": "internal/console/instancecopy.go", "text": "This instance never sleeps, so we don't copy it yet."},
- {"id": "backups.why.ownaddress", "file": "internal/console/instancecopy.go", "text": "It runs outside the platform, so we can't copy it."},
- {"id": "backups.why.notinstance", "file": "internal/console/instancecopy.go", "text": "{host} is a redirect or site, with no database."},
- {"id": "backups.why.demo", "file": "internal/console/instancecopy.go", "text": "Demo data isn't kept."},
- {"id": "backups.why.pooled", "file": "internal/console/instancecopy.go", "text": "Copies of pooled instances aren't shown here yet."},
- {"id": "backups.why.fleet", "file": "internal/console/instancecopy.go", "text": "Copies on your own servers aren't shown here yet."},
- {"id": "backups.why.otherregion", "file": "internal/console/instancecopy.go", "text": "Copies in {region} aren't shown here yet. Use the command line below to get one.", "note": "Re-approved by Paul on 2026-11-11 in copy review 2jhfdd2h7oiirvygyoivpyq2ja (approved-copy-2): the first approval's \"You can still download one.\" promised a Download button the page doesn't have."},
- {"id": "backups.why.nothingyet", "file": "internal/console/instancecopy.go", "text": "Check back in a minute."},
+ {"id": "backups.why.nosleep", "file": "internal/backupswords/words.go", "text": "This instance never sleeps, so we don't copy it yet."},
+ {"id": "backups.why.ownaddress", "file": "internal/backupswords/words.go", "text": "It runs outside the platform, so we can't copy it."},
+ {"id": "backups.why.notinstance", "file": "internal/backupswords/words.go", "text": "{host} is a redirect or site, with no database."},
+ {"id": "backups.why.demo", "file": "internal/backupswords/words.go", "text": "Demo data isn't kept."},
+ {"id": "backups.why.pooled", "file": "internal/backupswords/words.go", "text": "Copies of pooled instances aren't shown here yet."},
+ {"id": "backups.why.fleet", "file": "internal/backupswords/words.go", "text": "Copies on your own servers aren't shown here yet."},
+ {"id": "backups.why.otherregion", "file": "internal/backupswords/words.go", "text": "Copies in {region} aren't shown here yet. Use the command line below to get one.", "note": "Re-approved by Paul on 2026-11-11 in copy review 2jhfdd2h7oiirvygyoivpyq2ja (approved-copy-2): the first approval's \"You can still download one.\" promised a Download button the page doesn't have."},
+ {"id": "backups.why.nothingyet", "file": "internal/backupswords/words.go", "text": "Check back in a minute."},
{"id": "backups.cli.summary", "file": "internal/console/instancecopy.go", "text": "Use the command line"},
- {"id": "backups.cli.latest", "file": "internal/console/instancecopy.go", "text": "The latest copy:"},
- {"id": "backups.cli.at", "file": "internal/console/instancecopy.go", "text": "As it was at a given time:"},
- {"id": "backups.cli.heading", "file": "instances_backups.go", "text": "Backups for {host}", "pending": "slice 1 task 5"}
+ {"id": "backups.cli.latest", "file": "internal/backupswords/words.go", "text": "The latest copy:"},
+ {"id": "backups.cli.at", "file": "internal/backupswords/words.go", "text": "As it was at a given time:"},
+ {"id": "backups.cli.heading", "file": "instances_backups.go", "text": "Backups for {host}"}
]
}
diff --git a/instances_backups.go b/instances_backups.go
new file mode 100644
index 000000000..68b62c59c
--- /dev/null
+++ b/instances_backups.go
@@ -0,0 +1,229 @@
+// `carlos instances backups`: what the console knows about one instance's
+// copy (member backups spec 2026-11-11 §1), from the backups door
+// (internal/console/apibackups.go). It prints the facts the instance page's
+// Backups section shows, as label/value lines, in the page's approved words
+// (internal/backupswords).
+package main
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "flag"
+ "fmt"
+ "io"
+ "net/http"
+ "net/url"
+ "os"
+ "strings"
+ "time"
+
+ "github.com/carlosframework/platform/internal/backupswords"
+)
+
+const instancesBackupsUsage = `usage: carlos instances backups --app <a> [--instance <host>] [--json] [flags]
+`
+
+// backupsHeading is the first line, approved as backups.cli.heading.
+const backupsHeading = "Backups for {host}"
+
+// backupsJSON is the door's answer (the console's backupsView): the class,
+// the reason when there is one, the region for other_region, the copy's
+// newest point and the start of its history when they were read, and what
+// is kept of the files on disk.
+type backupsJSON struct {
+ Class string `json:"class"`
+ Reason string `json:"reason,omitempty"`
+ Region string `json:"region,omitempty"`
+ CopiedTo *struct {
+ Transaction uint64 `json:"transaction"`
+ WrittenAt time.Time `json:"written_at"`
+ } `json:"copied_to,omitempty"`
+ HistoryFrom *time.Time `json:"history_from,omitempty"`
+ Files string `json:"files"`
+}
+
+// runInstancesBackups is the registry leaf: instancesBackups, exiting with
+// its status.
+func runInstancesBackups(args []string) {
+ if code := instancesBackups(context.Background(), args, stdout, os.Stderr); code != 0 {
+ os.Exit(code)
+ }
+}
+
+// instancesBackups parses the flags, resolves the session, account and app
+// (fatal on refusal, as every API verb is), then shows the backups.
+func instancesBackups(ctx context.Context, args []string, stdout, stderr io.Writer) int {
+ fs := flag.NewFlagSet("instances backups", flag.ContinueOnError)
+ fs.SetOutput(stderr)
+ app := appFlag(fs, "app the instance belongs to")
+ instance := fs.String("instance", "", "the instance (may be left out when the app has one)")
+ asJSON := fs.Bool("json", false, "print the console's answer as JSON")
+ acctRaw, acctIDRaw, _ := accountFlags(fs)
+ consoleFlag := consoleOption(fs, "console to read through (default: the only logged-in one)")
+ fs.Usage = flagUsage(fs, instancesBackupsUsage)
+ if err := fs.Parse(args); err != nil {
+ if errors.Is(err, flag.ErrHelp) {
+ return 0
+ }
+ return 2
+ }
+ if fs.NArg() != 0 {
+ fs.Usage()
+ return 2
+ }
+ sess := requireAPISession("backups", *consoleFlag)
+ acct := resolvedAccount(sess, acctRaw, acctIDRaw)
+ name := resolvedApp(sess, acct, strings.TrimSpace(*app), instancesBackupsUsage)
+ return backupsShow(ctx, sess, acct, name, strings.TrimSpace(*instance), *asJSON, stdout, stderr)
+}
+
+// backupsShow picks the instance (resolveDBInstance: --instance, or the
+// app's only one), asks the door, and prints its answer.
+func backupsShow(ctx context.Context, sess *apiSession, acct apiAcct, app, instance string, asJSON bool, stdout, stderr io.Writer) int {
+ fail := func(err error) int {
+ fmt.Fprintf(stderr, "carlos instances backups: %v\n", err)
+ return 1
+ }
+ host, err := resolveDBInstance(ctx, sess, acct, app, instance)
+ if err != nil {
+ return fail(err)
+ }
+ st, body, err := sess.getJSON(ctx, apiPath(acct, app, "/instances/"+url.PathEscape(host)+"/backups"))
+ if err != nil {
+ return fail(err)
+ }
+ if st != http.StatusOK {
+ return fail(apiErrorFromBody(st, body))
+ }
+ if asJSON {
+ stdout.Write(body)
+ fmt.Fprintln(stdout)
+ return 0
+ }
+ var v backupsJSON
+ if err := json.Unmarshal(body, &v); err != nil {
+ return fail(fmt.Errorf("unreadable response: %w", err))
+ }
+ printBackups(stdout, app, host, v, time.Now())
+ return 0
+}
+
+// printBackups writes v as the instance page lays it out
+// (backupsSectionFor, internal/console/instancepage.go): the three tile
+// rows when the copy's newest point is known, the two "What we keep" rows
+// with their chips, the one reason line when a row needs one, and the two
+// db pull commands when db pull can serve the instance. Times are UTC, as
+// on the page; now decides "today" and the --at example.
+func printBackups(w io.Writer, app, host string, v backupsJSON, now time.Time) {
+ now = now.UTC()
+ files := backupswords.ChipNotShown
+ if v.Files == "not_copied" {
+ files = backupswords.ChipNotCopied
+ }
+ var db, why string
+ pull := false
+ switch v.Class {
+ case "replicated":
+ db, pull = backupswords.ChipCopied, true
+ case "no_copy":
+ db = backupswords.ChipNotCopied
+ default:
+ db = backupswords.ChipNotShown
+ }
+ switch v.Reason {
+ case "no_sleep":
+ why = backupswords.WhyNoSleep
+ case "own_address":
+ why = backupswords.WhyOwnAddress
+ case "not_instance":
+ why = strings.ReplaceAll(backupswords.WhyNotInstance, "{host}", host)
+ case "demo":
+ why = backupswords.WhyDemo
+ case "pooled":
+ why = backupswords.WhyPooled
+ case "fleet":
+ why = backupswords.WhyFleet
+ case "other_region":
+ // db pull forwards to the instance's region.
+ why = strings.ReplaceAll(backupswords.WhyOtherRegion, "{region}", v.Region)
+ pull = true
+ case "nothing_replicated":
+ db, why = backupswords.ChipNothingYet, backupswords.WhyNothingYet
+ case "too_large_to_plan":
+ // Too large for the console to plan; db pull plans it here.
+ db, pull = backupswords.ChipUnavailable, true
+ case "unavailable":
+ db = backupswords.ChipUnavailable
+ }
+
+ type row struct{ label, value string }
+ var rows []row
+ var from *time.Time
+ if v.Class == "replicated" && v.CopiedTo != nil {
+ saved := v.CopiedTo.WrittenAt.UTC()
+ day := backupsDate(saved, now, "Mon 2 Jan")
+ if saved.Year() == now.Year() && saved.YearDay() == now.YearDay() {
+ day = backupswords.SavedToday
+ }
+ history := "—"
+ if v.HistoryFrom != nil {
+ h := v.HistoryFrom.UTC()
+ from = &h
+ history = backupsDate(h, now, "2 Jan") + " (" + backupswords.HistoryDetail + ")"
+ }
+ rows = append(rows,
+ row{backupswords.SavedLabel, saved.Format("15:04") + " UTC " + day},
+ row{backupswords.HistoryLabel, history},
+ row{backupswords.TestLabel, "— (" + backupswords.TestNone + ")"})
+ }
+ rows = append(rows, row{backupswords.KeepDB, db}, row{backupswords.KeepFiles, files})
+
+ width := 0
+ for _, r := range []string{backupswords.SavedLabel, backupswords.HistoryLabel, backupswords.TestLabel, backupswords.KeepDB, backupswords.KeepFiles} {
+ width = max(width, len(r))
+ }
+ fmt.Fprintln(w, strings.ReplaceAll(backupsHeading, "{host}", host))
+ for _, r := range rows {
+ fmt.Fprintf(w, "%-*s %s\n", width, r.label, r.value)
+ }
+ if why != "" {
+ fmt.Fprintf(w, "\n%s\n", why)
+ }
+ if pull {
+ // db pull needs --out, a path that doesn't exist yet: the host's
+ // first label, and for --at the time too, so the two don't clash.
+ file, _, _ := strings.Cut(host, ".")
+ at := backupsAtExample(from, now)
+ fmt.Fprintf(w, "\n%s\n carlos db pull --app %s --instance %s --out %s.db\n", backupswords.CLILatest, app, host, file)
+ fmt.Fprintf(w, "\n%s\n carlos db pull --app %s --instance %s --at %s --out %s-%s.db\n",
+ backupswords.CLIAt, app, host, at.Format(time.RFC3339), file, at.Format("20060102T1504Z"))
+ }
+}
+
+// backupsDate is t in layout, with the year when it isn't now's.
+func backupsDate(t, now time.Time, layout string) string {
+ if t.Year() != now.Year() {
+ layout += " 2006"
+ }
+ return t.Format(layout)
+}
+
+// backupsAtExample is the --at in the second command, as the page picks
+// it: a day before now, on the hour, unless the kept history starts later,
+// and then the first whole minute inside it. db pull refuses a time after
+// now and one before the history.
+func backupsAtExample(from *time.Time, now time.Time) time.Time {
+ at := now.UTC().Add(-24 * time.Hour).Truncate(time.Hour)
+ if from == nil || !at.Before(*from) {
+ return at
+ }
+ at = from.Truncate(time.Minute)
+ if at.Before(*from) {
+ at = at.Add(time.Minute)
+ }
+ if at.After(now) {
+ at = *from
+ }
+ return at
+}
diff --git a/instances_backups_test.go b/instances_backups_test.go
new file mode 100644
index 000000000..1336a813e
--- /dev/null
+++ b/instances_backups_test.go
@@ -0,0 +1,308 @@
+package main
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/backupswords"
+)
+
+// backupsTestNow is the clock every printBackups case reads.
+var backupsTestNow = time.Date(2026, 11, 11, 15, 0, 0, 0, time.UTC)
+
+const backupsTestHost = "shop-1.shop.example.com"
+
+// The pull commands the page shows for backupsTestHost at backupsTestNow
+// with history from 4 Nov: --at is a day before now, on the hour.
+const (
+ backupsTestPullLatest = "carlos db pull --app shop --instance shop-1.shop.example.com --out shop-1.db"
+ backupsTestPullAt = "carlos db pull --app shop --instance shop-1.shop.example.com --at 2026-11-10T15:00:00Z --out shop-1-20261110T1500Z.db"
+)
+
+func backupsTestView(t *testing.T, body string) backupsJSON {
+ t.Helper()
+ var v backupsJSON
+ if err := json.Unmarshal([]byte(body), &v); err != nil {
+ t.Fatal(err)
+ }
+ return v
+}
+
+// A replicated instance prints the page's facts as label/value lines, the
+// labels aligned, then the two db pull commands under their intros.
+func TestInstancesBackupsPrintsLines(t *testing.T) {
+ v := backupsTestView(t, `{"class":"replicated","copied_to":{"transaction":42,"written_at":"2026-11-11T14:02:31Z"},"history_from":"2026-11-04T09:12:00Z","files":"not_copied"}`)
+ var out bytes.Buffer
+ printBackups(&out, "shop", backupsTestHost, v, backupsTestNow)
+ want := "Backups for shop-1.shop.example.com\n" +
+ "Last change saved 14:02 UTC today\n" +
+ "Go back as far as 4 Nov (about 7 days of history)\n" +
+ "Restore test — (not shown yet)\n" +
+ "Database Copied\n" +
+ "Files on disk Not copied\n" +
+ "\n" +
+ "The latest copy:\n" +
+ " " + backupsTestPullLatest + "\n" +
+ "\n" +
+ "As it was at a given time:\n" +
+ " " + backupsTestPullAt + "\n"
+ if out.String() != want {
+ t.Fatalf("replicated:\n%s\nwant:\n%s", out.String(), want)
+ }
+}
+
+// Every class and reason the door answers prints the page's chips and its
+// one reason line, tiles only for a read copy, and the commands only where
+// db pull can serve the instance. No state says "backed up", "up to date",
+// "current", or wears a tick.
+func TestInstancesBackupsPrintsEachClass(t *testing.T) {
+ cases := []struct {
+ name, body string
+ db, files string
+ why string
+ tiles bool
+ pull bool
+ lines []string
+ }{
+ {name: "replicated, history unknown, born HA",
+ body: `{"class":"replicated","copied_to":{"transaction":42,"written_at":"2026-11-09T08:30:00Z"},"files":"not_shown"}`,
+ db: backupswords.ChipCopied, files: backupswords.ChipNotShown, tiles: true, pull: true,
+ lines: []string{"Last change saved 08:30 UTC Mon 9 Nov", "Go back as far as —"}},
+ {name: "last year",
+ body: `{"class":"replicated","copied_to":{"transaction":42,"written_at":"2025-12-31T23:00:00Z"},"history_from":"2025-12-30T10:00:00Z","files":"not_copied"}`,
+ db: backupswords.ChipCopied, files: backupswords.ChipNotCopied, tiles: true, pull: true,
+ lines: []string{"Last change saved 23:00 UTC Wed 31 Dec 2025", "Go back as far as 30 Dec 2025 (about 7 days of history)"}},
+ {name: "never sleeps", body: `{"class":"no_copy","reason":"no_sleep","files":"not_copied"}`,
+ db: backupswords.ChipNotCopied, files: backupswords.ChipNotCopied, why: backupswords.WhyNoSleep},
+ {name: "own address", body: `{"class":"no_copy","reason":"own_address","files":"not_copied"}`,
+ db: backupswords.ChipNotCopied, files: backupswords.ChipNotCopied, why: backupswords.WhyOwnAddress},
+ {name: "not an instance", body: `{"class":"no_copy","reason":"not_instance","files":"not_copied"}`,
+ db: backupswords.ChipNotCopied, files: backupswords.ChipNotCopied, why: "shop-1.shop.example.com is a redirect or site, with no database."},
+ {name: "demo", body: `{"class":"no_copy","reason":"demo","files":"not_copied"}`,
+ db: backupswords.ChipNotCopied, files: backupswords.ChipNotCopied, why: backupswords.WhyDemo},
+ {name: "pooled", body: `{"class":"not_shown","reason":"pooled","files":"not_copied"}`,
+ db: backupswords.ChipNotShown, files: backupswords.ChipNotCopied, why: backupswords.WhyPooled},
+ {name: "fleet", body: `{"class":"not_shown","reason":"fleet","files":"not_shown"}`,
+ db: backupswords.ChipNotShown, files: backupswords.ChipNotShown, why: backupswords.WhyFleet},
+ {name: "other region", body: `{"class":"not_shown","reason":"other_region","region":"London","files":"not_copied"}`,
+ db: backupswords.ChipNotShown, files: backupswords.ChipNotCopied, pull: true,
+ why: "Copies in London aren't shown here yet. Use the command line below to get one."},
+ {name: "nothing yet", body: `{"class":"not_shown","reason":"nothing_replicated","files":"not_copied"}`,
+ db: backupswords.ChipNothingYet, files: backupswords.ChipNotCopied, why: backupswords.WhyNothingYet},
+ {name: "too large", body: `{"class":"not_shown","reason":"too_large_to_plan","files":"not_copied"}`,
+ db: backupswords.ChipUnavailable, files: backupswords.ChipNotCopied, pull: true},
+ {name: "unavailable", body: `{"class":"not_shown","reason":"unavailable","files":"not_copied"}`,
+ db: backupswords.ChipUnavailable, files: backupswords.ChipNotCopied},
+ }
+ for _, c := range cases {
+ t.Run(c.name, func(t *testing.T) {
+ var out bytes.Buffer
+ printBackups(&out, "shop", backupsTestHost, backupsTestView(t, c.body), backupsTestNow)
+ got := out.String()
+ lines := strings.Split(got, "\n")
+ if lines[0] != "Backups for "+backupsTestHost {
+ t.Errorf("heading = %q", lines[0])
+ }
+ for _, want := range append([]string{
+ "Database " + c.db,
+ "Files on disk " + c.files,
+ }, c.lines...) {
+ if !containsLine(lines, want) {
+ t.Errorf("no line %q in:\n%s", want, got)
+ }
+ }
+ for _, label := range []string{backupswords.SavedLabel, backupswords.HistoryLabel, backupswords.TestLabel} {
+ if strings.Contains(got, label) != c.tiles {
+ t.Errorf("%q shown = %v, want %v:\n%s", label, !c.tiles, c.tiles, got)
+ }
+ }
+ if c.why != "" && !containsLine(lines, c.why) {
+ t.Errorf("no reason line %q in:\n%s", c.why, got)
+ }
+ if c.why == "" {
+ for _, w := range backupsWhyLines() {
+ // The text after the placeholders, which every
+ // filled-in line ends with.
+ tail := w[strings.LastIndex(w, "}")+1:]
+ if strings.Contains(got, tail) {
+ t.Errorf("a reason line where the page shows none:\n%s", got)
+ }
+ }
+ }
+ for _, intro := range []string{backupswords.CLILatest, backupswords.CLIAt} {
+ if containsLine(lines, intro) != c.pull {
+ t.Errorf("%q shown = %v, want %v:\n%s", intro, !c.pull, c.pull, got)
+ }
+ }
+ if strings.Contains(got, "carlos db pull") != c.pull {
+ t.Errorf("db pull shown = %v, want %v:\n%s", !c.pull, c.pull, got)
+ }
+ lower := strings.ToLower(got)
+ for _, banned := range []string{"backed up", "up to date", "current", "✓", "✔"} {
+ if strings.Contains(lower, banned) {
+ t.Errorf("output says %q:\n%s", banned, got)
+ }
+ }
+ })
+ }
+}
+
+func backupsWhyLines() []string {
+ return []string{backupswords.WhyNoSleep, backupswords.WhyOwnAddress, backupswords.WhyNotInstance,
+ backupswords.WhyDemo, backupswords.WhyPooled, backupswords.WhyFleet, backupswords.WhyOtherRegion,
+ backupswords.WhyNothingYet}
+}
+
+func containsLine(lines []string, want string) bool {
+ for _, l := range lines {
+ if l == want {
+ return true
+ }
+ }
+ return false
+}
+
+// backupsConsole is a fake console: the instance list answers list, the
+// backups door answers status and body, and every path asked is kept.
+func backupsConsole(t *testing.T, list string, status int, body string) (*httptest.Server, *[]string) {
+ t.Helper()
+ var paths []string
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ paths = append(paths, r.URL.RequestURI())
+ if r.Method != http.MethodGet {
+ t.Errorf("method %s", r.Method)
+ }
+ if r.Header.Get("Authorization") == "" {
+ t.Error("no bearer token")
+ }
+ w.Header().Set("Content-Type", "application/json")
+ if strings.HasSuffix(r.URL.Path, "/instances") {
+ w.Write([]byte(list))
+ return
+ }
+ w.WriteHeader(status)
+ w.Write([]byte(body))
+ }))
+ t.Cleanup(ts.Close)
+ return ts, &paths
+}
+
+// backupsServiceEnv signs the in-process CLI in with a service token
+// against ts, as CI would, with no store env to put it in direct mode.
+func backupsServiceEnv(t *testing.T, ts *httptest.Server) []string {
+ t.Setenv("CARLOS_DEPLOYMENT_BUCKET", "")
+ t.Setenv("CARLOS_DEPLOYMENT_DIR", "")
+ t.Setenv("CARLOS_SERVICE_TOKEN", "svc-secret")
+ t.Setenv("CARLOS_CONSOLE", "")
+ return []string{"--console", ts.URL, "--account", "bab", "--app", "shop"}
+}
+
+const backupsTestBody = `{"class":"replicated","copied_to":{"transaction":42,"written_at":"2026-11-11T14:02:31Z"},"history_from":"2026-11-04T09:12:00Z","files":"not_copied"}`
+
+// The verb asks the door's exact path for the named instance, and nothing
+// else.
+func TestInstancesBackupsRequestPath(t *testing.T) {
+ ts, paths := backupsConsole(t, `{"instances":[]}`, http.StatusOK, backupsTestBody)
+ args := append(backupsServiceEnv(t, ts), "--instance", backupsTestHost)
+ var out, errb bytes.Buffer
+ if code := instancesBackups(context.Background(), args, &out, &errb); code != 0 {
+ t.Fatalf("exit %d: %s", code, errb.String())
+ }
+ want := "/api/cli/apps/bab/shop/instances/shop-1.shop.example.com/backups"
+ if len(*paths) != 1 || (*paths)[0] != want {
+ t.Fatalf("paths = %v, want [%s]", *paths, want)
+ }
+ if !strings.HasPrefix(out.String(), "Backups for "+backupsTestHost+"\n") {
+ t.Fatalf("output:\n%s", out.String())
+ }
+}
+
+// --json prints the door's body as it came, plus a newline.
+func TestInstancesBackupsJSON(t *testing.T) {
+ ts, _ := backupsConsole(t, `{"instances":[]}`, http.StatusOK, backupsTestBody)
+ args := append(backupsServiceEnv(t, ts), "--instance", backupsTestHost, "--json")
+ var out, errb bytes.Buffer
+ if code := instancesBackups(context.Background(), args, &out, &errb); code != 0 {
+ t.Fatalf("exit %d: %s", code, errb.String())
+ }
+ if out.String() != backupsTestBody+"\n" {
+ t.Fatalf("--json = %q, want the body and a newline", out.String())
+ }
+}
+
+// A refusal from the door, the shared 429 included, prints the standard
+// apiErrorFromBody message and exits 1 with nothing on stdout.
+func TestInstancesBackupsRefusal(t *testing.T) {
+ cases := []struct {
+ status int
+ body string
+ want string
+ }{
+ {http.StatusTooManyRequests, `{"error":"too many requests, retry in a minute"}`, "too many requests, retry in a minute"},
+ {http.StatusNotFound, "404 page not found\n", errMembershipNotFound.Error()},
+ {http.StatusBadGateway, `{"error":"could not read the instance"}`, "could not read the instance"},
+ }
+ for _, c := range cases {
+ ts, _ := backupsConsole(t, `{"instances":[]}`, c.status, c.body)
+ args := append(backupsServiceEnv(t, ts), "--instance", backupsTestHost)
+ var out, errb bytes.Buffer
+ if code := instancesBackups(context.Background(), args, &out, &errb); code != 1 {
+ t.Fatalf("%d: exit %d, want 1", c.status, code)
+ }
+ if out.Len() != 0 {
+ t.Errorf("%d: stdout %q", c.status, out.String())
+ }
+ want := "carlos instances backups: " + apiErrorFromBody(c.status, []byte(c.body)).Error() + "\n"
+ if errb.String() != want || !strings.Contains(want, c.want) {
+ t.Errorf("%d: stderr %q, want %q", c.status, errb.String(), want)
+ }
+ }
+}
+
+// With no --instance, an app with one instance uses it; one with several
+// refuses, naming them, before asking the door anything.
+func TestInstancesBackupsPicksOnlyInstance(t *testing.T) {
+ ts, paths := backupsConsole(t, `{"instances":[{"host":"shop-1.shop.example.com"}]}`, http.StatusOK, backupsTestBody)
+ var out, errb bytes.Buffer
+ if code := backupsShow(context.Background(), newTestSession(ts.URL), apiAcct{Seg: "bab"}, "shop", "", false, &out, &errb); code != 0 {
+ t.Fatalf("one instance: exit %d: %s", code, errb.String())
+ }
+ if last := (*paths)[len(*paths)-1]; last != "/api/cli/apps/bab/shop/instances/shop-1.shop.example.com/backups" {
+ t.Fatalf("one instance asked %v", *paths)
+ }
+
+ ts, paths = backupsConsole(t, `{"instances":[{"host":"b.shop.example.com"},{"host":"a.shop.example.com"}]}`, http.StatusOK, backupsTestBody)
+ out.Reset()
+ errb.Reset()
+ if code := backupsShow(context.Background(), newTestSession(ts.URL), apiAcct{Seg: "bab"}, "shop", "", false, &out, &errb); code != 1 {
+ t.Fatalf("two instances: exit %d, want 1", code)
+ }
+ if !strings.Contains(errb.String(), "--instance") || !strings.Contains(errb.String(), "a.shop.example.com, b.shop.example.com") {
+ t.Fatalf("two instances: %q, want a refusal naming both", errb.String())
+ }
+ for _, p := range *paths {
+ if strings.HasSuffix(p, "/backups") {
+ t.Fatalf("asked the door with no instance chosen: %v", *paths)
+ }
+ }
+}
+
+// Flags it can't read are the person's to fix: usage on stderr, exit 2,
+// and no request.
+func TestInstancesBackupsBadArgs(t *testing.T) {
+ for _, args := range [][]string{{"--nope"}, {"extra"}} {
+ var out, errb bytes.Buffer
+ if code := instancesBackups(context.Background(), args, &out, &errb); code != 2 {
+ t.Errorf("%v: exit %d, want 2", args, code)
+ }
+ if !strings.Contains(errb.String(), "usage: carlos instances backups") {
+ t.Errorf("%v: no usage in %q", args, errb.String())
+ }
+ }
+}
diff --git a/internal/backupswords/words.go b/internal/backupswords/words.go
new file mode 100644
index 000000000..5e90be515
--- /dev/null
+++ b/internal/backupswords/words.go
@@ -0,0 +1,41 @@
+// Package backupswords holds the member backups phrases that both the
+// console's instance page and `carlos instances backups` show: the labels,
+// the chips, the reason lines and the db pull intros. One home, so the page
+// and the terminal never word one fact two ways. Every string here is
+// approved copy, pinned by the member backups copy record
+// (docs/superpowers/plans/member-backups-slice1-copy.json, ids backups.*).
+// {host} and {region} are filled in when the line is shown.
+//
+// A leaf: it imports nothing, so the root CLI can use it without taking on
+// the console.
+package backupswords
+
+const (
+ SavedLabel = "Last change saved"
+ SavedToday = "today"
+ HistoryLabel = "Go back as far as"
+ HistoryDetail = "about 7 days of history"
+ TestLabel = "Restore test"
+ TestNone = "not shown yet"
+
+ KeepDB = "Database"
+ KeepFiles = "Files on disk"
+
+ ChipCopied = "Copied"
+ ChipNotCopied = "Not copied"
+ ChipNotShown = "Not shown here"
+ ChipNothingYet = "Nothing yet"
+ ChipUnavailable = "Can't read now"
+
+ WhyNoSleep = "This instance never sleeps, so we don't copy it yet."
+ WhyOwnAddress = "It runs outside the platform, so we can't copy it."
+ WhyNotInstance = "{host} is a redirect or site, with no database."
+ WhyDemo = "Demo data isn't kept."
+ WhyPooled = "Copies of pooled instances aren't shown here yet."
+ WhyFleet = "Copies on your own servers aren't shown here yet."
+ WhyOtherRegion = "Copies in {region} aren't shown here yet. Use the command line below to get one."
+ WhyNothingYet = "Check back in a minute."
+
+ CLILatest = "The latest copy:"
+ CLIAt = "As it was at a given time:"
+)
diff --git a/internal/console/instancecopy.go b/internal/console/instancecopy.go
index 684eedaf5..ad19bd93c 100644
--- a/internal/console/instancecopy.go
+++ b/internal/console/instancecopy.go
@@ -1,5 +1,7 @@
package console
+import "github.com/carlosframework/platform/internal/backupswords"
+
type instanceCopyStrings struct {
AllChannels, GroupChannel, Open, Observed, Target, LastReading, NoReadings, PendingVersion string
}
@@ -30,7 +32,9 @@ func (p page) InstanceAllURL() string {
// backupsCopyStrings is the instance page's Backups section, the member
// backups copy review of 2026-11-11 (record:
// docs/superpowers/plans/member-backups-slice1-copy.json, ids backups.*).
-// {host} and {region} are filled in when the line is shown.
+// {host} and {region} are filled in when the line is shown. The strings
+// `carlos instances backups` shows too live in internal/backupswords; the
+// page-only ones are here.
type backupsCopyStrings struct {
Heading, SavedLabel, SavedToday, HistoryLabel, HistoryDetail, TestLabel, TestNone string
KeepHeading, KeepDB, KeepFiles string
@@ -42,31 +46,31 @@ type backupsCopyStrings struct {
var backupsCopy = backupsCopyStrings{
Heading: "Backups",
- SavedLabel: "Last change saved",
- SavedToday: "today",
- HistoryLabel: "Go back as far as",
- HistoryDetail: "about 7 days of history",
- TestLabel: "Restore test",
- TestNone: "not shown yet",
+ SavedLabel: backupswords.SavedLabel,
+ SavedToday: backupswords.SavedToday,
+ HistoryLabel: backupswords.HistoryLabel,
+ HistoryDetail: backupswords.HistoryDetail,
+ TestLabel: backupswords.TestLabel,
+ TestNone: backupswords.TestNone,
KeepHeading: "What we keep",
- KeepDB: "Database",
- KeepFiles: "Files on disk",
- ChipCopied: "Copied",
- ChipNotCopied: "Not copied",
- ChipNotShown: "Not shown here",
- ChipNothingYet: "Nothing yet",
- ChipUnavailable: "Can't read now",
- WhyNoSleep: "This instance never sleeps, so we don't copy it yet.",
- WhyOwnAddress: "It runs outside the platform, so we can't copy it.",
- WhyNotInstance: "{host} is a redirect or site, with no database.",
- WhyDemo: "Demo data isn't kept.",
- WhyPooled: "Copies of pooled instances aren't shown here yet.",
- WhyFleet: "Copies on your own servers aren't shown here yet.",
- WhyOtherRegion: "Copies in {region} aren't shown here yet. Use the command line below to get one.",
- WhyNothingYet: "Check back in a minute.",
+ KeepDB: backupswords.KeepDB,
+ KeepFiles: backupswords.KeepFiles,
+ ChipCopied: backupswords.ChipCopied,
+ ChipNotCopied: backupswords.ChipNotCopied,
+ ChipNotShown: backupswords.ChipNotShown,
+ ChipNothingYet: backupswords.ChipNothingYet,
+ ChipUnavailable: backupswords.ChipUnavailable,
+ WhyNoSleep: backupswords.WhyNoSleep,
+ WhyOwnAddress: backupswords.WhyOwnAddress,
+ WhyNotInstance: backupswords.WhyNotInstance,
+ WhyDemo: backupswords.WhyDemo,
+ WhyPooled: backupswords.WhyPooled,
+ WhyFleet: backupswords.WhyFleet,
+ WhyOtherRegion: backupswords.WhyOtherRegion,
+ WhyNothingYet: backupswords.WhyNothingYet,
CLISummary: "Use the command line",
- CLILatest: "The latest copy:",
- CLIAt: "As it was at a given time:",
+ CLILatest: backupswords.CLILatest,
+ CLIAt: backupswords.CLIAt,
}
func (p page) BackupsCopy() backupsCopyStrings { return backupsCopy }
diff --git a/parity/cli.tsv b/parity/cli.tsv
index 0281a0587..42fe051df 100644
--- a/parity/cli.tsv
+++ b/parity/cli.tsv
@@ -118,6 +118,7 @@ instance-exit box-local - - - - -
instance-probe box-local - - - - -
instance-stop box-local - - - - -
instances box-local - - - - -
+instances backups customer - - - - -
instances create customer - - - - -
instances delete customer - - - - -
instances door-key create customer - - - - -
diff --git a/parity/parity.tsv b/parity/parity.tsv
index b3a5081d6..b0fa048e7 100644
--- a/parity/parity.tsv
+++ b/parity/parity.tsv
@@ -71,6 +71,7 @@ instances-set-pages instances gap instances set-pages wp-instances Page cachin
instances-updates instances both instances set [--updates,--major,--pin] POST /a/{sqid}/apps/{app}/instances/{host}/updates
instances-update instances both instances update POST /a/{sqid}/apps/{app}/instances/{host}/updates/install
instances-retry instances both instances retry POST /a/{sqid}/apps/{app}/instances/{host}/retry
+instances-backups instances both instances backups GET /a/{sqid}/apps/{app}/instances/{host}
steering instances gap steering wp-instances
routes instances partial routes GET /a/{sqid}/apps/{app}/instances ; GET /a/{sqid}/apps/{app}/settings/{section} The console shows host and channel but no environment or replication column.
restart instances partial restart POST /a/{sqid}/apps/{app}/restart ; POST /a/{sqid}/apps/{app}/instances/{host}/restart The console has no environment scope and no dry-run list.