You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The backup is downloaded to the local backup directory before restoration. The downloaded file is automatically cleaned up after the restore completes.
120
120
:::
121
121
122
+
### Restore the most recent backup
123
+
124
+
If you do not want to name an archive — for example from a scheduled job, which cannot know a filename in advance — pass `--latest` instead of a file:
125
+
126
+
```bash
127
+
infrahub-backup restore --latest
128
+
```
129
+
130
+
`--latest` lists the configured backup directory, ranks the archives it finds, and restores the newest one. To rank archives in the configured S3 bucket and prefix instead, add `--s3`:
Exactly one location is consulted per run. With `--s3` the local backup directory is never read; without it the bucket is never read. The two are never merged, and there is no fallback from one to the other.
137
+
138
+
Everything else about the restore is unchanged: `--latest` only decides which archive is used. Metadata validation, checksum verification, and the container stop and start sequence all behave exactly as they do when you name an archive, and every other `restore` flag composes with `--latest`.
139
+
140
+
#### How the newest archive is chosen
141
+
142
+
`--latest` ranks archives exactly as the retention policy ranks them:
143
+
144
+
- Only names matching `infrahub_backup_<YYYYMMDD_HHMMSS>.tar.gz`, optionally with an `.enc` suffix, take part. Anything else in the directory or under the prefix — unrelated files, partial uploads, foreign names — is ignored.
145
+
- Archives are ordered by the timestamp embedded in the name, newest first, with ties broken by name in descending order.
146
+
147
+
Because the ordering is shared with retention, the archive `--latest` restores is always one that retention's "the most recent backup at each location always survives" rule protects. See [Manage backup retention](./retention.mdx).
148
+
149
+
Before the restore begins, the run reports what it selected and where it came from:
150
+
151
+
```text
152
+
INFO[0000] Restoring latest backup infrahub_backup_20250929_143022.tar.gz from local:/opt/infrahub_backups
153
+
```
154
+
155
+
The location reads `local:<directory>` for the backup directory and `s3://<bucket>/<prefix>` for a bucket. That single line is what makes an unattended restore auditable from captured output alone, without access to the machine that ran it.
156
+
157
+
#### When `--latest` refuses to run
158
+
159
+
`--latest` fails rather than guessing, and it never falls back to an older archive:
160
+
161
+
| Situation | Result |
162
+
|------|-------------|
163
+
| No matching archives in the selected location | Non-zero exit naming the location that was listed. This is the expected state before the first backup runs. |
164
+
| The newest archive is encrypted and no `--decrypt-key` was passed | Non-zero exit naming the archive. The check runs before the `--sleep` wait, before any download, and before any container is stopped. |
165
+
| Both `--latest` and an archive name are passed | Non-zero exit. The two are mutually exclusive. |
166
+
|`--s3` is passed without `--latest`| Non-zero exit. To restore one exact remote archive, pass its `s3://` URI as the argument instead. |
167
+
168
+
Restoring whichever archive happens to be readable would leave a deployment holding stale data while reporting success. On a schedule nobody watches, that is worse than a job that visibly fails.
169
+
170
+
:::info
171
+
Because the selection happens before the `--sleep` wait, an archive transferred into place during the sleep is not considered by `--latest`. The wait exists so that a *named* file can be transferred in; with `--latest` the choice has already been made.
172
+
:::
173
+
174
+
:::info
175
+
With `--latest --s3` the selected object is downloaded to a temporary file inside the backup directory and removed afterwards. A local archive sharing the selected object's name — what `create --s3-upload --s3-keep-local` leaves behind — is never overwritten and never deleted.
176
+
:::
177
+
178
+
#### Refresh staging from production on a schedule
179
+
180
+
To keep a staging deployment on the newest production backup, run `restore --latest --s3` against the bucket production uploads to. Because no filename is involved, the job is stable across every backup production takes:
181
+
182
+
```bash
183
+
# /etc/cron.d/infrahub-staging-sync
184
+
# Refresh staging from the newest production backup, nightly at 03:00.
Add `--reset-deployment-id` as shown, so the refreshed staging instance does not report the production deployment ID. Capture the job's output: the selection line above is the record of which production backup staging is currently running.
191
+
192
+
:::danger
193
+
A scheduled restore replaces all data in the deployment it targets. Confirm that `--project` — or the environment the job runs in — points at the deployment you intend to overwrite before enabling the schedule, and keep the production deployment out of reach of the job entirely.
|`--latest`| Restore the most recent backup instead of naming an archive; mutually exclusive with the argument |`false`|
112
+
|`--s3`| With `--latest`: choose from the configured S3 bucket and prefix instead of the local backup directory |`false`|
110
113
|`--exclude-taskmanager`| Skip restoring the task manager database even if the dump is present |`false`|
111
114
|`--migrate-format`| Run Neo4j database format migration after restore |`false`|
115
+
|`--sleep <duration>`| Wait this long before the restore begins, for manual file transfer |`0`|
116
+
|`--decrypt-key <path>`| Private key PEM file for decrypting an encrypted backup | - |
112
117
|`--reset-deployment-id`| Generate a new Root node UUID after restore to detach this instance from the source deployment ID |`false`|
113
118
119
+
`--latest` and `--s3` are per-invocation switches with no environment variable behind them: a persistent `--latest` would turn a mistyped `restore` into a data-overwriting default, and a persistent `--s3` would silently move the location every restore reads.
120
+
121
+
`--latest` ranks archives exactly as retention does — by the timestamp embedded in the name, newest first, ties broken by name descending — and only names matching `infrahub_backup_<YYYYMMDD_HHMMSS>.tar.gz[.enc]` take part. Exactly one location is consulted per run, and the two are never merged.
122
+
123
+
The run exits non-zero without touching the deployment when the selected location holds no archives, when the newest archive is encrypted and no `--decrypt-key` was passed, when `--latest` is combined with an archive name, or when `--s3` is passed without `--latest`. `--latest` never falls back to an older archive. See [Restore from a backup](../backup/restore.mdx).
0 commit comments