In Barman, how do retention_policy = REDUNDANCY 3 and RECOVERY WINDOW OF 7 DAYS differ, and what actually enforces them?
answer
- a count versus a time span
- the backup before the window
- WAL follows the backups
- cron, not a manual command
- minimum_redundancy and keep
basics
~20 sREDUNDANCY 3 keeps the three newest full backups. RECOVERY WINDOW OF 7 DAYS keeps the backups and WAL needed to recover to any moment of the last seven days, including the newest backup before the window. barman cron enforces both; unset means nothing is deleted.
solid answer
~50 s`retention_policy` accepts `REDUNDANCY n` or `RECOVERY WINDOW OF n {DAYS | WEEKS | MONTHS}`, globally or per server, and is **unset by default**, so Barman deletes nothing. `REDUNDANCY 3` keeps the three newest DONE full backups and marks older ones obsolete; it promises nothing about how far back you can recover. `RECOVERY WINDOW OF 7 DAYS` promises point-in-time recovery to any moment of the last seven days, so Barman keeps the newest backup that started before the window plus all WAL after it, and only older backups and WAL become obsolete. WAL retention follows the backups (`wal_retention_policy = main`). Enforcement is part of `barman cron`. Two guards sit on top: `minimum_redundancy` refuses a delete that would leave fewer full backups, and `barman keep --target full|standalone` exempts an archival backup. Block-level incrementals are judged by their root backup.
code
ini · 8 lines# /etc/barman.conf
[barman]
retention_policy = RECOVERY WINDOW OF 14 DAYS
minimum_redundancy = 2
# /etc/barman.d/telemetry-pg.conf
[telemetry-pg]
retention_policy = REDUNDANCY 4go deeper
Recall the two policy forms, that the option is unset by default, and that barman cron applies it.
Explain why a recovery window keeps the backup before the window, how WAL retention follows, and what minimum_redundancy and keep add.
Size Barman storage for a policy given backup frequency and WAL volume, and choose keep targets for archival copies without hoarding WAL.
Turn a stated recovery promise into per-server policies across a fleet, balancing disk cost against how far back each database must be recoverable.
## The setting and its syntax Barman's `retention_policy` option decides which base backups, and therefore which archived WAL, become **obsolete** and get removed. It can be set in the `[barman]` global section or per server: `retention_policy = {REDUNDANCY value | RECOVERY WINDOW OF value {DAYS | WEEKS | MONTHS}}` The value must be a positive integer. The option is **empty by default**, which means no retention at all: backups and WAL accumulate until someone deletes them or the disk fills. Only backups with status `DONE` count; failed backups and those still `WAITING_FOR_WALS` are ignored by the policy. ## REDUNDANCY versus RECOVERY WINDOW | | `REDUNDANCY 3` | `RECOVERY WINDOW OF 7 DAYS` | |---|---|---| | Measures | number of full backups | a span of time ending now | | Keeps | the three newest backups | every backup and WAL file needed to reach any point in the last 7 days | | Recovery promise | none about time | PITR to any moment of the last 7 days | | Disk use depends on | backup frequency | backup frequency and WAL volume | `REDUNDANCY` is easy to reason about for disk, but if backups stop or run more often, the time span it covers changes silently. `RECOVERY WINDOW` states the business promise directly. ## Why the window keeps one older backup To recover to a moment just inside the window, PostgreSQL must start from a base backup taken **before** that moment and replay WAL forward. So with a 7-day window Barman keeps: 1. every backup inside the window; 2. the **newest backup that falls outside** the window, together with all WAL from its start onward; 3. nothing older: earlier backups and earlier WAL are marked obsolete. With weekly full backups on Sundays, on a Saturday the oldest kept backup can be almost two weeks old, plus two weeks of WAL. That is the main reason a recovery window uses more disk than people expect; more frequent backups shorten it. ## Who enforces it Retention is applied by **`barman cron`** during its maintenance run, not by `barman backup` and not only by a manual `barman delete`. If cron is not scheduled, the policy is configured but never applied. `barman delete SERVER BACKUP_ID` removes a single backup by hand and is subject to the same `minimum_redundancy` guard, and deleting a full backup that has block-level incrementals removes its whole chain. When there is no Barman server at all, as with the barman-cloud scripts, `barman-cloud-backup-delete -r "RECOVERY WINDOW OF 30 DAYS"` applies the same policy syntax and must be scheduled by you. ## Safety rails on top of the policy - **`minimum_redundancy`** (default `0`): Barman refuses to delete a full backup when doing so would leave fewer than this many DONE full backups, and `barman check` reports `minimum redundancy requirements` as failed when there are too few. A `REDUNDANCY` value below `minimum_redundancy` is raised to it, with a warning in the log. - **`barman keep`** marks an archival backup that retention never deletes: - `--target full` keeps the backup **and all WAL after it**, so it can still be recovered to any later point; - `--target standalone` keeps only the WAL needed to make that backup consistent, a snapshot of one moment; - `--status` shows the mark, `--release` removes it. - **Block-level incrementals** are not counted on their own. Retention looks at the chain's root: if the root becomes obsolete, so do its incrementals; a `KEEP:FULL` root keeps them all. `barman keep` refuses an incremental backup. ## Pitfalls - Leaving `retention_policy` unset on a busy server and discovering it when the backup volume fills. - Expecting `REDUNDANCY 7` with nightly backups to mean seven days, then adding an extra manual backup and losing a day of recoverability. - Setting `minimum_redundancy` higher than a `REDUNDANCY` value and not noticing the log warning: Barman quietly keeps the larger number of backups. - Keeping a monthly archival backup with `--target full` when `standalone` was meant, and retaining a month of WAL along with it.
- What is the difference between barman keep --target full and --target standalone?Both exempt the backup from the retention policy indefinitely. `full` also keeps all WAL from that backup onward, so you can still recover from it to any later point. `standalone` keeps only the WAL needed to make that backup consistent, so it restores the database exactly as it was then and costs far less space.
- Why can a RECOVERY WINDOW OF 7 DAYS policy hold much more than seven days of data?To recover to the first minute of the window Barman must keep the newest backup taken before it, plus all WAL from that backup's start. With weekly full backups that backup can be nearly two weeks old, so up to two weeks of WAL stays on disk. Taking backups more often shrinks the overhang.
A recovery window is like promising to replay a ship's route from any hour of the last week: the log entries are not enough, you also need the last position fix taken before the week began, so that fix is kept even though it is older than the week.
- Barman applies a seven-day retention policy out of the box
- REDUNDANCY 3 guarantees recovery to any point of the last three days
- A 7-day recovery window deletes every backup older than seven days
- Retention only happens when you run barman delete by hand
- minimum_redundancy is the number of backups barman takes per day