Commit 2a42b02
feat: support non-interactive appsmithctl restore for automation (#42147)
## Description
Adds a non-interactive mode to `appsmithctl restore` so instance
restores can run unattended in CI/CD pipelines — requested by a customer
for automated disaster recovery.
Linear: https://linear.app/appsmith/issue/APP-15482
New surface:
```bash
appsmithctl restore --backup-file=<name> [--non-interactive] [--force]
```
- `--backup-file=<name>` — selects a backup by file name (as shown in
the interactive listing), skipping the index prompt. Values containing
path separators are rejected; the name must match an actual archive in
the backup directory.
- `--non-interactive` — suppresses every prompt (parity with
`appsmithctl backup`). Any input that would have been prompted for must
come from a flag or env var, otherwise the command exits 1 with a
message naming what is missing — **before** services are stopped or the
database is touched.
- `--force` — proceeds despite an Appsmith version mismatch between
backup and instance (non-interactive mode only; the interactive
Enter-to-continue prompt is unchanged). It bypasses only the version
gate — missing/wrong passwords, unknown file names, and missing
encryption keys still exit 1.
- `APPSMITH_BACKUP_ARCHIVE_PASSWORD` — supplies the archive decryption
password (single attempt). The password reaches openssl via the child
process environment (`-pass env:`), never argv, so it is not visible in
the process table. Verified compatible with archives encrypted by the
existing backup flow (`-k`), via a real openssl round-trip.
- Unencrypted archives restored non-interactively use the instance's
existing `APPSMITH_ENCRYPTION_PASSWORD`/`APPSMITH_ENCRYPTION_SALT`; both
are validated up-front (`ensureEncryptionKeysPresent`, exported and
unit-tested), and the check runs again defensively at the point of use
in `restoreDockerEnvFile`.
Hardening/fixes riding with the feature (same concern — the new env var
and the restore flow):
- A failed decryption used to exit **0**; it now exits 1.
- `APPSMITH_BACKUP_ARCHIVE_PASSWORD=` is stripped from the `docker.env`
bundled into future backup archives (`removeSensitiveEnvData`), so an
operator who wrongly persists the transient secret does not leak it into
archives. The `=` suffix keeps `APPSMITH_BACKUP_ARCHIVE_LIMIT` intact.
- `run()`'s failure path now logs to stderr.
## Impact on existing instances
- **Fresh install**: no change; all new behavior is opt-in via flags/env
var.
- **Upgrade from default**: no change to interactive restore, with one
exception — if `APPSMITH_BACKUP_ARCHIVE_PASSWORD` is set in the
environment, the interactive password prompt is skipped and the env
value is used (single attempt).
- **Upgrade from customized**: scripts that (incorrectly) relied on exit
code 0 from a failed decryption will now see exit 1 — this was a bug
fix; a failed restore should never report success.
- **Rollback**: older images silently ignore the new flags (`restore`
never rejected unknown args), so a pipeline built on `--non-interactive`
will **hang at an interactive prompt** rather than fail loudly.
Pipelines must pin an image version at or above this release.
## Deliberate scope decisions
- `APPSMITH_BACKUP_ARCHIVE_PASSWORD` is intentionally **not** added to
`.env.example`, Helm values, or the Heroku README: it is a
per-invocation CI secret, not instance configuration. Persisting it in
`docker.env` is exactly the mistake the new strip-list entry guards
against. It should be supplied ephemerally, e.g. `docker exec -e
APPSMITH_BACKUP_ARCHIVE_PASSWORD=... <container> appsmithctl restore
...`.
- `--force` without `--non-interactive` is a no-op (the interactive
version prompt still appears). Unattended use requires
`--non-interactive`.
- Non-interactive restore assumes same-instance encryption keys;
restoring another instance's backup requires exporting that instance's
`APPSMITH_ENCRYPTION_PASSWORD`/`SALT` into the environment first.
- Restore is fail-fast, not atomic: all validation happens before any
mutation, but a `mongorestore` failure mid-run still leaves a partially
restored instance (pre-existing behavior, unchanged).
- Restore-by-index and a positional `restore <file>` form are omitted
(the issue allows "CLI flags and/or environment variables"; an index is
racy in automation).
- Follow-ups tracked separately: backup-side `encryptBackupArchive`
still passes its password on the openssl argv (pre-existing, same fix
pattern applies); non-interactive `appsmithctl backup` never encrypts,
so a fully automated *encrypted* backup→restore pipeline needs a
backup-side counterpart; `run()`-level orchestration tests.
## Call sites checked
- All six `readlineSync.question` sites in `restore.ts` are gated for
non-interactive mode (backup index, decrypt password loop, both
encryption-key prompt paths, version-mismatch confirm); the test suite's
default `readlineSync.question` mock throws, so any reachable prompt
fails CI.
- openssl password sinks: restore's `runDecryptCommand` fixed here;
backup's `encryptBackupArchive` deliberately deferred (follow-up above).
- `removeSensitiveEnvData` is the only path that writes env content into
archives; covered.
## CE/EE note
`restore.ts` already diverges in EE (S3 archive support), so the hourly
sync will conflict on this file. The EE-side end state is prepared on a
branch (includes the S3-aware `--backup-file` handling and an EE-only
correction of the version-mismatch message, which wrongly named the
`appsmith-ce` image) and will be used as the source of truth when
resolving the bot's sync PR.
## Testing
- New `restore.test.ts` (15 tests): `--backup-file`
selection/unknown-name/path-guard, non-interactive-without-file failure,
env-password decrypt (asserts password absent from argv and present in
child env; single attempt on wrong password),
non-interactive-without-env failure, interactive prompt regression
tests, `ensureEncryptionKeysPresent` (3 cases), version gate (abort /
`--force` / match).
- Tests were verified red against the pre-fix source, and
mutation-checked (each behavior individually neutered kills its own
tests).
- Full `src/ctl` jest suite: 54/54 pass; eslint and `tsc --noEmit`
clean.
- Real openssl round-trip: archive encrypted with `-k` decrypts with
`-pass env:`.
- In-container end-to-end smoke test against
`appsmith/appsmith-ce:release` with this branch's ctl bundle: 10
scenarios, all passing — full results in [this
comment](#42147 (comment)).
## Automation
/ok-to-test tags="@tag.All"
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: Cypress test results -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/34380403090>
> Commit: 4c389a6
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=34380403090&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Wed, 09 Sep 2026 19:11:12 UTC
<!-- end of auto-generated comment: Cypress test results -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added non-interactive restore support with explicit backup-file
selection.
* Added optional force restore for version mismatches.
* Added support for archive passwords supplied through environment
settings.
* Added validation for encryption keys, backup files, and archive
decryption.
* **Bug Fixes**
* Sensitive archive passwords are no longer included in exported
environment files.
* Restore errors now fail clearly and return an appropriate error
status.
* **Tests**
* Expanded coverage for backup selection, decryption, encryption
validation, and restore compatibility.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent cda4e09 commit 2a42b02
4 files changed
Lines changed: 368 additions & 26 deletions
File tree
- app/client/packages/rts/src/ctl
- backup
- links
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
128 | 139 | | |
129 | 140 | | |
130 | 141 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
0 commit comments