# borg prune

    borg [common options] prune [options] [NAME]

positional arguments
| `NAME` | specify the archive name
options
| `-n`, `--dry-run` | do not change the repository
| `--list` | output a verbose list of archives it keeps/prunes
| `--short` | use a less wide archive part format
| `--list-pruned` | output verbose list of archives it prunes
| `--list-kept` | output verbose list of archives it keeps
| `--format FORMAT` | specify format for the archive part (default: “{archive:<36} {time} [{id}]”)
| `--json` | Format output as JSON. The form of `--format` is ignored, but keys used in it are added to the JSON output. Some keys are always present. Note: JSON can only represent text.
| `--from TIMESTAMP` | only consider archives older than this for pruning
| `--keep` | number or time interval of archives to keep
| `--keep-secondly` | number or time interval of secondly archives to keep
| `--keep-minutely` | number or time interval of minutely archives to keep
| `-H`, `--keep-hourly` | number or time interval of hourly archives to keep
| `-d`, `--keep-daily` | number or time interval of daily archives to keep
| `-w`, `--keep-weekly` | number or time interval of weekly archives to keep
| `-m`, `--keep-monthly` | number or time interval of monthly archives to keep
| `--keep-13weekly` | number or time interval of quarterly archives to keep (13 week strategy)
| `--keep-3monthly` | number or time interval of quarterly archives to keep (3 month strategy)
| `-y`, `--keep-yearly` | number or time interval of yearly archives to keep
Common options
Archive filters — Archive filters can be applied to repository targets.
| `-a PATTERN`, `--match-archives PATTERN` | only consider archives matching all patterns. See “borg help match-archives”.
| `--oldest TIMESPAN` | consider archives between the oldest archive’s timestamp and (oldest + TIMESPAN), e.g., 7d or 12m.
| `--newest TIMESPAN` | consider archives between the newest archive’s timestamp and (newest - TIMESPAN), e.g., 7d or 12m.
| `--older TIMESPAN` | consider archives older than (now - TIMESPAN), e.g., 7d or 12m.
| `--newer TIMESPAN` | consider archives newer than (now - TIMESPAN), e.g., 7d or 12m.

## Description

The prune command prunes a repository by soft-deleting all archives not matching any of the specified retention options.

Important:

- The prune command will only mark archives for deletion (“soft-deletion”), repository disk space is not freed until you run `borg compact`.

- You can use `borg undelete` to undelete archives, but only until you run `borg compact`.

This command is normally used by automated backup scripts wanting to keep a certain number of historic backups. This retention policy is commonly referred to as GFS (Grandfather-father-son) backup rotation scheme.

The recommended way to use prune is to give the archive series name to it via the NAME argument (assuming you have the same name for all archives in a series). Alternatively, you can also use --match-archives (-a), then only archives that match the pattern are considered for deletion and only those archives count towards the totals specified by the rules. Otherwise, all archives in the repository are candidates for deletion! There is no automatic distinction between archives representing different contents. These need to be distinguished by specifying matching globs.

If you have multiple series of archives with different data sets (e.g. from different machines) in one shared repository, use one prune call per series.

The `--keep` option is the simplest way to specify a basic retention policy. It accepts a count or a time interval for retention (e.g. `10` or `7d`, `4w`). With a count it keeps at most that many recent archives; with an interval it keeps all archives created within that time window. When `--from` is given together with an interval retention, the interval is measured backwards from that timestamp instead of from the current time. See `Date and Time` docs for exact INTERVAL format.

The `--keep-secondly`, `--keep-minutely`, `--keep-hourly`, `--keep-daily`, `--keep-weekly`, `--keep-monthly`, `--keep-13weekly`, `--keep-3monthly`, and `--keep-yearly` options specify time period retention policies. They accept either a count N for retention or a time interval INTERVAL for retention, same as for `--keep`. With a retention count, they keep at most that many archives (one per period, e.g. one per day or one per month until the retention count is met). With a retention interval, they keep one archive per period within that time span (e.g. at most one per day in a span of seven days, even if some days had none) -- measured from `--from` if given, otherwise from the current time. Specifying a count of `-1` (or the word `all`) means no limit. A zero count or zero-length interval keeps nothing.

The `--from` option restricts pruning to archives older than the given TIMESTAMP. Archives made at or after this timestamp are kept unconditionally as a pre-filter. When `--from` is used together with interval-based `--keep-*` options (e.g. `--keep-daily 7d`), the interval is measured backwards from the given timestamp rather than from the current time. Count-based retention does not count the unconditionally kept archives.

The `--keep-13weekly` and `--keep-3monthly` rules are two different strategies for keeping archives every quarter year.

The oldest archive is kept as long as the coarsest retention rule covers it -- `--keep-yearly=3` will keep the oldest archive if it couldn’t otherwise find three candidates, `--keep-yearly=5y` will keep the oldest archive as long as it is at or within the 5y interval. This is useful for rolling tiered backup schemes, where the earliest backup in a retention window should survive until the next tier’s interval naturally replaces it.

When using interval-based pruning with multiple `--keep-*` options, the intervals must be specified in increasing length matching the periods chosen. For example, `--keep-daily 7d --keep-weekly 4w` is valid, but `--keep-daily 30d --keep-weekly 7d` is not, because the weekly interval is already covered by the daily one and so the weekly interval is effectively useless. An error is emitted upon running `borg prune` if such a combination of flags is given. The order of flags on the command line is not significant.

A practical approach for recurring backups is to use rules with increasing coarseness so that most of recent history is kept and older history gradually thins out with time. For example, `--keep-daily 7d --keep-weekly 4w --keep-monthly 6` keeps an archive per day for the past week, per week for the past month, and one per month for six months after that. Combine this with `--from` to align time windows to calendar boundaries rather than the exact moment you run prune for more predictable behavior of coarser rules: `--keep-daily 7d --keep-weekly 4w --from $(date +%F)`.

Count-based retention keeps archives less bound to time. For instance, `--keep-yearly 3` retains 3 yearly archives however far back they span and `--keep-daily 20` keeps 20 archives no matter if you missed a week in between. This can be useful for less regular archive creation, or if your use case does not map well to specific time intervals, or if you simply prefer to think of archive retention in numbers rather than intervals.

For count-based retention, backups selected by more granular rules do not count towards those of coarser rules. `--keep 3 --keep-monthly 2` will first keep the 3 latest archives and then keep 2 monthly archives, skipping ones that were already kept by `--keep 3`.

The time that each archive creation started is used to match archives to pruning periods. Dates and times are interpreted in the local timezone of your system. Weeks go from Monday to Sunday.

You can influence how the `--list` output is formatted by using the `--short` option (less wide output) or by giving a custom format using `--format` (see the `borg repo-list` description for more details about the format string).

## Examples

Be careful: prune is a potentially dangerous command that removes backup archives.

By default, prune applies to all archives in the repository unless you restrict its operation to a subset of the archives.

The recommended way to name archives (with `borg create`) is to use the identical archive name within a series of archives. Then you can simply give that name to prune as well, so it operates only on that series of archives.

Alternatively, you can use `-a`/`--match-archives` to match archive names and select a subset of them. When using `-a`, be careful to choose a good pattern — for example, do not use a prefix “foo” if you do not also want to match “foobar”.

It is strongly recommended to always run `prune -v --list --dry-run ...` first, so you will see what it would do without it actually doing anything.

Do not forget to run `borg compact -v` after prune to actually free disk space.

The `--keep-*` options accept either a count (e.g. `--keep-daily 7`) or a time interval (e.g. `--keep-daily 7d`). A count keeps up to N archives per period (e.g. the last 7 daily archives), while an interval keeps one archive per period within that time span (e.g. one daily archive per day in the last 7-day window). When using intervals, you may also specify `--from` to set the reference timestamp for interval calculation.

    # Keep 7 end of day and 4 additional end of week archives.
    # Do a dry-run without actually deleting anything.
    $ borg prune -v --list --dry-run --keep-daily=7 --keep-weekly=4

    # Similar to the above, but only apply to the archive series named '{hostname}':
    $ borg prune -v --list --keep-daily=7 --keep-weekly=4 '{hostname}'

    # Similar to the above, but apply to archive names starting with the hostname
    # of the machine followed by a '-' character:
    $ borg prune -v --list --keep-daily=7 --keep-weekly=4 -a 'sh:{hostname}-*'

    # Keep 7 end of day, 4 additional end of week archives,
    # and an end of month archive for every month:
    $ borg prune -v --list --keep-daily=7 --keep-weekly=4 --keep-monthly=-1

    # Keep all backups in the last 10 days, 4 additional end of week archives,
    # and an end of month archive for every month:
    $ borg prune -v --list --keep=10d --keep-weekly=4 --keep-monthly=-1

    # Keep daily archives from the last 7 days:
    $ borg prune -v --list --dry-run --keep-daily=7d

    # Same as above, but with a fixed reference timestamp:
    $ borg prune -v --list --dry-run --from 2025-12-01T00:00:00+02:00 --keep-daily=7d

    # Keep the last 14 archives using `--keep`:
    $ borg prune -v --list --dry-run --keep 14

    # Keep all archives from the last 30 days using `--keep`:
    $ borg prune -v --list --dry-run --keep 30d

There are also visualized prune examples in `docs/misc/prune-example.txt` and `docs/misc/prune-example-interval.txt`:

    borg prune visualized
    =====================

    Assume it is 2016-01-01. Today's archive has not yet been made. You have
    created at least one archive on each day in 2015 except on 2015-12-19 (no
    backup was made on that day), and you started backing up with Borg on
    2015-01-01.

    This is what borg prune --keep-daily 14 --keep-monthly 6 --keep-yearly 1
    would keep.

    Archives kept by the --keep-daily rule are marked by a "d" to the right,
    archives kept by the --keep-monthly rule are marked by a "m" to the right, and
    archives kept by the --keep-yearly rule are marked by a "y" to the right.

    Calendar view
    -------------

                                2015
          January               February               March
    Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
              1y 2  3  4                     1                     1
     5  6  7  8  9 10 11   2  3  4  5  6  7  8   2  3  4  5  6  7  8
    12 13 14 15 16 17 18   9 10 11 12 13 14 15   9 10 11 12 13 14 15
    19 20 21 22 23 24 25  16 17 18 19 20 21 22  16 17 18 19 20 21 22
    26 27 28 29 30 31     23 24 25 26 27 28     23 24 25 26 27 28 29
                                                30 31

           April                  May                   June
    Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
           1  2  3  4  5               1  2  3   1  2  3  4  5  6  7
     6  7  8  9 10 11 12   4  5  6  7  8  9 10   8  9 10 11 12 13 14
    13 14 15 16 17 18 19  11 12 13 14 15 16 17  15 16 17 18 19 20 21
    20 21 22 23 24 25 26  18 19 20 21 22 23 24  22 23 24 25 26 27 28
    27 28 29 30           25 26 27 28 29 30 31  29 30m

            July                 August              September
    Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
           1  2  3  4  5                  1  2      1  2  3  4  5  6
     6  7  8  9 10 11 12   3  4  5  6  7  8  9   7  8  9 10 11 12 13
    13 14 15 16 17 18 19  10 11 12 13 14 15 16  14 15 16 17 18 19 20
    20 21 22 23 24 25 26  17 18 19 20 21 22 23  21 22 23 24 25 26 27
    27 28 29 30 31m       24 25 26 27 28 29 30  28 29 30m
                          31m

          October               November              December
    Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
              1  2  3  4                     1      1  2  3  4  5  6
     5  6  7  8  9 10 11   2  3  4  5  6  7  8   7  8  9 10 11 12 13
    12 13 14 15 16 17 18   9 10 11 12 13 14 15  14 15 16 17d18d19 20d
    19 20 21 22 23 24 25  16 17 18 19 20 21 22  21d22d23d24d25d26d27d
    26 27 28 29 30 31m    23 24 25 26 27 28 29  28d29d30d31d
                          30m

    List view
    ---------

    --keep-daily 14     --keep-monthly 6     --keep-yearly 1
    ----------------------------------------------------------------
     1. 2015-12-31       (2015-12-31 kept     (2015-12-31 kept
     2. 2015-12-30        by daily rule)       by daily rule)
     3. 2015-12-29       1. 2015-11-30        1. 2015-01-01 (oldest)
     4. 2015-12-28       2. 2015-10-31
     5. 2015-12-27       3. 2015-09-30
     6. 2015-12-26       4. 2015-08-31
     7. 2015-12-25       5. 2015-07-31
     8. 2015-12-24       6. 2015-06-30
     9. 2015-12-23
    10. 2015-12-22
    11. 2015-12-21
    12. 2015-12-20
        (no archive made on 2015-12-19)
    13. 2015-12-18
    14. 2015-12-17

    Notes
    -----

    2015-12-31 is kept due to the --keep-daily 14 rule (because it is applied
    first), not due to the --keep-monthly or --keep-yearly rule.

    Rules are applied in the order given: archives already kept by an earlier
    rule are excluded from consideration by later rules.

    The --keep-yearly 1 rule does not consider the December 31st archive because it
    has already been kept due to the daily rule. There are no archives from
    previous years, so there are no "true" yearly candidates. The oldest archive at
    2015-01-01 fills the remaining slot and will be kept until the rolling backup
    scheme reaches "steady state" (when all retention rules are fully satisfied).

    The --keep-monthly 6 rule keeps Nov, Oct, Sep, Aug, Jul and Jun. December is
    not considered for this rule, because that archive was already kept because of
    the daily rule.

    2015-12-17 is kept to satisfy the --keep-daily 14 rule, because no archive was
    made on 2015-12-19. If an archive had been made on that day, it would not keep
    the archive from 2015-12-17.

    We did not include weekly, hourly, minutely, or secondly rules to keep this
    example simple. They all work in basically the same way.

    The weekly rule is easy to understand roughly, but hard to understand in all
    details. If you are interested, read "ISO 8601:2000 standard week-based year".

    The 13weekly and 3monthly rules are two different strategies for keeping one
    archive every quarter of a year. There are `multiple ways` to define a
    quarter-year; borg prune recognizes two:

    * --keep-13weekly keeps one archive every 13 weeks using ISO 8601:2000's
      definition of the week-based year. January 4th is always included in the
      first week of a year, and January 1st to 3rd may be in week 52 or 53 of the
      previous year. Week 53 is also in the fourth quarter of the year.
    * --keep-3monthly keeps one archive every 3 months. January 1st to March 31,
      April 1st to June 30th, July 1st to September 30th, and October 1st to
      December 31st form the quarters.

    If the subtleties of the definition of a quarter-year don't matter to you, a
    short summary of behavior is:

    * --keep-13weekly favors keeping archives at the beginning of Jan, Apr, Jul,
      and Oct.
    * --keep-3monthly favors keeping archives at the end of Dec, Mar, Jun, and Sep.
    * Both strategies will have some overlap in which archives are kept.
    * The differences are negligible unless archives considered for deletion were
      created weekly or more frequently.

    .. _multiple ways: https://en.wikipedia.org/wiki/Calendar_year#Quarter_year

    borg prune visualized (count and interval mixed)
    ================================================================================

    Scenario: You use borg to perform daily backups. As backups age, the day-to-day
    changes become less important, so to save storage space you want older archives
    to "thin out" over time while retaining most recent archives. Your backup
    script runs `borg create`, immediately followed by `borg prune`.

    Assume today is 2026-06-04 and you always start your backups at 16:00. You have
    been creating backup archives starting at 16:00, followed by pruning, on most
    days going back to late 2025. Today, `borg create` took a little longer than
    usual. It's 16:12 now and you run `borg prune`.

    You want Borg to keep one archive per day for one week, four weekly archives,
    one archive per month for five months, and two yearly backups. For that, you
    use the following command:

    ```
    borg prune \
      --keep-daily 1w \
      --keep-weekly 4 \
      --keep-monthly 5m \
      --keep-yearly 2 \
      --from '2026-06-04 16:00'
    ```

    The `--keep-*` options reflect the intended retention policy exactly. Note the
    different wording in the retention policy for weekly and yearly archives: They
    aren't *interval*-based, but *count*-based.

    Another important detail here is `--from`. Without it, intervals would be
    calculated relative to the actual start time of `prune` - in this case 16:12.
    Since your backups are always created at 16:00, this 12-minute shift would move
    the cutoff point of intervals and could cause archives near the boundary to
    unexpectedly fall outside the expected time window.

    By specifying `--from '2026-06-04 16:00'`, all intervals are anchored to the
    intended reference time (16:00), not the moment `prune` happens to run. This
    ensures stable and predictable retention behavior, independent of when `prune`
    actually runs.

    The first archive was made on 2025-11-15. You missed the backups on 2026-03-31,
    2026-05-24, and 2026-06-03.

    Below you find an overview of what archives `prune` will keep.

    Archives kept by the `--keep-daily` rule are marked by a "d" to the right,
    archives kept by the `--keep-weekly` rule are marked by a "w" to the right,
    archives kept by the `--keep-monthly` rule are marked by a "m" to the right,
    archives kept by the `--keep-yearly` rule are marked by a "y" to the right, and
    archives kept by the `--from` rule are marked by a "x" to the right.

    Calendar view
    -------------
                                2025
                                November              December
                                                 1  2  3  4  5  6  7
                                                 8  9 10 11 12 13 14
                                         15y16  15 16 17 18 19 20 21
                          17 18 19 20 21 22 23  22 23 24 25 26 27 28
                          24 25 26 27 28 29 30  29 30 31m

                                2026
          January               February               March
              1  2  3  4                     1                     1
     5  6  7  8  9 10 11   2  3  4  5  6  7  8   2  3  4  5  6  7  8
    12 13 14 15 16 17 18   9 10 11 12 13 14 15   9 10 11 12 13 14 15
    19 20 21 22 23 24 25  16 17 18 19 20 21 22  16 17 18 19 20 21 22
    26 27 28 29 30 31m    23 24 25 26 27 28m    23 24 25 26 27 28 29
                                                30m31

           April                  May                   June
           1  2  3  4  5               1  2  3w  1d 2d 3  4x
     6  7  8  9 10 11 12   4  5  6  7  8  9 10w
    13 14 15 16 17 18 19  11 12 13 14 15 16 17w
    20 21 22 23 24 25 26  18 19 20 21 22 23w24
    27 28 29 30m          25 26 27 28d29d30d31d

    List view
    ---------

    --keep-daily 1w     --keep-weekly 4     --keep-monthly 5m   --keep-yearly 2
    --------------------------------------------------------------------------------
                                                                1. 2025-11-15 (oldest)
    1. 2026-06-02       1. 2026-05-23       1. 2026-04-30
    2. 2026-06-01       2. 2026-05-17       2. 2026-03-30
    3. 2026-05-31       3. 2026-05-10       3. 2026-02-28
    4. 2026-05-30       4. 2026-05-03       4. 2026-01-31
    5. 2026-05-29                           5. 2025-12-31
    6. 2026-05-28

    2026-06-04 is additionally kept due to `--from`.

    Notes
    -----

    The current day's archive is always kept, because `create` ran after the date
    given with `--from`. For `prune`, it's as if this archive doesn't exist (yet).

    2026-06-03 was skipped, so no archive can be kept with `--keep-daily` for that
    day. Other than with a *count*-based policy, no compensation is made for an
    *interval* like `--keep-daily 1w`, so the rule simply keeps one archive fewer.

    2026-05-28 16:00 is exactly one week before `--from`. Since `create` always
    runs after 16:00, the archive created on 2026-05-28 is kept, too. Without
    `--from`, Borg would cut off at 2026-05-28 16:12 instead, which would likely
    mean that the archive created on 2026-05-28 would be pruned. `--from` ensures
    that 2026-05-28 is consistently kept. If you want it consistently pruned, try a
    later reference time, e.g. `--from '2026-06-04 23:59:59'`.

    2026-05-31 is considered not only by `--keep-daily`, but by `--keep-weekly`
    and `--keep-monthly`, too. The archive is effectively kept by `--keep-daily`,
    but how this affects other rules differs between *count*- and *interval*-based
    policies. For *interval*-based rules like `--keep-monthly 5m` it has no effect:
    The rule simply keeps one archive fewer in that case.

    For *count*-based rules like `--keep-weekly 4` it has an effect: The policy
    tells Borg to keep 4 weekly archives. Weekly slots are identified by ISO week
    number; in this example the four kept archives cover weeks 18 through 21. If
    2026-05-31 is kept by another rule already, Borg compensates by keeping an
    older archive instead. Consequently, Borg will also keep the 2026-05-03 archive.

    The week 22 slot is consumed by that same 2026-05-31 archive. Any other
    archive from that week is not kept by weekly, even if it falls within the
    daily window boundary. This is why 2026-05-27 is pruned: it has just fallen
    out of the daily window, and no other rule covers it.

    Since 2026-05-24 and 2026-03-31 were skipped, Borg substitutes the next best
    candidate for each: 2026-05-23 fills the week 21 weekly slot, and 2026-03-30
    fills the March monthly slot.

    The implementation of `--keep-monthly 5m` is somewhat special: Borg defines a
    month as a fixed 31-day period, independent of the actual calendar dates
    involved. As a result, `5m` corresponds to 5 × 31 = 155 days. The archive from
    2025-12-31 16:00 is exactly 155 days older than the reference time and is
    therefore retained by `--keep-monthly`.

    As a result, there are no true yearly candidates. In the absence of a better
    candidate, `--keep-yearly 2` only matches the oldest archive, 2025-11-15.

    Since interval rules define time windows rather than competing for a fixed
    number of slots, their interplay is simpler than count-based rules. An archive
    is kept by an interval rule as long as it falls within the specified window;
    the next rule simply considers whatever remains.

    Intervals and counts can be mixed freely. Yearly retention in this example is
    done by retention count instead of intervals. A count rule paired with interval
    rules behaves just as it would if all preceding rules were also counts:
    Archives already kept by earlier rules are excluded from consideration. In this
    example, every yearly slot is consumed by earlier rules; no true yearly
    candidate remains, so the oldest archive at 2025-11-15 is kept to preserve
    rolling backup semantics.