Skip to content

mongoshield prune

Delete backups that the retention policy no longer keeps.

Terminal window
mongoshield prune [options]

Keeps the newest backup of each period (like restic/borg --keep-*). The newest backup, held backups and invalid backups are never removed. Without count flags the policy comes from retention in mongoshield.config.ts.

Only the backups of the configured source and selection (include/exclude) are pruned; backups of other sources or selections in the same storage are left alone. --all-sources applies the policy to every backup in the storage.

OptionDescription
--last <n>Keep the N newest backups.
--hourly <n>Keep the newest backup of each of the last N hours.
--daily <n>Keep the newest backup of each of the last N days.
--weekly <n>Keep the newest backup of each of the last N ISO weeks.
--monthly <n>Keep the newest backup of each of the last N months.
--yearly <n>Keep the newest backup of each of the last N years.
--min-verified <n>Always keep at least N verified backups.
--dry-runShow the plan and delete nothing.
--from <storage-url>Where backups are stored: ./dir, file:///abs, s3://bucket/prefix (default: config).
--uri <mongodb-uri>Source whose backups to prune (default: config source.uri, MONGODB_URI).
--include <pattern>The selection whose backups to prune (as backed up). Repeatable.
--exclude <pattern>The selection whose backups to prune (as backed up). Repeatable.
--scope-label <key=value>Prune only backups with this label, instead of the selection's shape. Repeatable.
--all-sourcesApply the policy to every backup in the storage, whoever wrote it.

The global options (--config, --json, --quiet, --verbose, --no-color, --yes) work here too.

Preview the configured policy:

Terminal window
mongoshield prune --dry-run

Keep 7 dailies, 4 weeklies and 12 monthlies, without prompting:

Terminal window
mongoshield prune --daily 7 --weekly 4 --monthly 12 --yes

Prune the backups of one selection in a shared bucket:

Terminal window
mongoshield prune --include 'app.orders' --last 24 --from s3://acme-backups/prod

Prune the backups labelled team=billing:

Terminal window
mongoshield prune --scope-label team=billing --daily 7

Apply one policy to every backup in the storage (asks first):

Terminal window
mongoshield prune --all-sources --daily 7