borg analyze

borg [common options] analyze [options]

options

--group-by KEYS

decompose the whole repository by groups of archives, grouped by the given comma-separated archive attributes (not combinable with archive filters); valid keys are: name, host, user, tags

--json

format output as JSON

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”.

--sort-by KEYS

Comma-separated list of sorting keys; valid keys are: timestamp, archive, name, id, tags, host, user; default is: timestamp

--first N

consider the first N archives after other filters are applied

--last N

consider the last N archives after other filters are applied

--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

Analyze the archives matching the usual archive selection options (e.g. -a series_name), or decompose the whole repository into groups of archives, see --group-by.

Deduplicated size of a set of archives

For the considered (matching) set of archives, borg analyze reports the source (uncompressed source data) and stored (compressed, as stored in the repository) size, plus the compression factor relating the two (stored / source):

  • the deduplicated size of the set: the summed size of the union of chunks the considered archives reference (chunks shared within the set are counted once);

  • the exclusive size of the set: the summed size of chunks referenced only by the considered set and by no other archive - i.e. the space that deleting the whole set would free (assuming the other archives stay).

Additionally, the unreferenced chunks are reported: chunks in the repository that no non-deleted archive references, i.e. what borg compact could free in the current state of the repository. Only their stored size is known - a chunk’s source size is only recorded in the archives that reference it. Note that chunks belonging to soft-deleted archives count as unreferenced here, although borg compact keeps them when the repository is damaged (so borg undelete stays possible).

If no archive filter is given, all archives are considered - every referenced chunk is then trivially exclusive to them, so only the repository-wide deduplicated size is shown.

The stored sizes come from the repository’s chunk index; the chunk membership and the source sizes come from the per-archive references cache that borg compact maintains, so unchanged archives usually do not need to be opened.

Decomposition by group of archives (--group-by)

With --group-by, the whole repository is decomposed into groups of archives instead. The groups are formed by the given comma-separated archive attributes name, host, user and tags - the same grouping borg prune --group-by uses, so the numbers below relate to the same units that prune applies its retention rules to.

Archives sharing a name form a series, so --group-by name usually groups all backups of one source. In a repository shared by multiple machines or users that is not specific enough, because they may use the same series name for their own, unrelated data - use --group-by name,host there.

Every chunk is counted in exactly one row, so the rows add up to the repository’s deduplicated size:

  • one row per group, showing what is exclusive to it: no archive of another group references these chunks, so deleting all archives of that group would free them;

  • one row for the chunks shared by two or more groups;

  • one row for the unreferenced chunks (see above).

This answers “which group costs how much, and what would I get back by dropping it” for all groups at once, in a single pass over the archives. As the shared and unreferenced rows can only be determined by looking at every archive, --group-by always covers the whole repository and cannot be combined with archive filters.

Grouping by more attributes moves chunks from the group rows into the shared row: if two hosts back up identical content, --group-by name reports it as exclusive to that name, while --group-by name,host correctly shows that deleting either host’s archives alone would not free it.

Hot spots

If at least two archives match, borg analyze additionally iterates over all matching archives, over all contained files, and collects information about chunks stored in all directories it encounters. It considers chunk IDs and their plaintext sizes and adds up the sizes of added and removed chunks per direct parent directory, and outputs a list of “directory: size”.

You can use that list to find directories with a lot of “activity” — maybe some of these are temporary or cache directories you forgot to exclude. To avoid including these unwanted directories in your backups, you can carefully exclude them in borg create (for future backups) or use borg recreate to recreate existing archives without them.

JSON output

With --json, the same numbers are emitted as a single JSON object instead of the text report, with raw byte values rather than formatted sizes. The default mode fills the dedup_size and hotspots keys, --group-by fills the by_group key. The compression factor is not included: it is stored_size / source_size.

See All about JSON: How to develop frontends for the object’s structure.

Examples

The examples below use a repository with three archive series: home (a home directory), projects (a subdirectory of that home directory, so it shares most of its data with home) and etc. The oldest home archive was deleted with borg delete, but borg compact has not been run yet.

Which series uses how much space, and what would deleting a whole series free?

$ borg analyze --group-by name

Repository decomposition by name
=================================================================================
8 archive(s) in 3 group(s)

group                           archives        source        stored  compression
name='home'                            3      45.41 MB      43.01 MB         0.95
name='projects'                        3     175.57 kB     127.78 kB         0.73
name='etc'                             2     633.63 kB      46.62 kB         0.07
(shared by 2+ groups)                          5.33 MB       2.15 MB         0.40
(unreferenced)                                     n/a      52.23 kB          n/a
---------------------------------------------------------------------------------
total (deduplicated)                   8      51.55 MB      45.33 MB         0.88

Unreferenced: 4 of 749 chunks in the repository index.

Each chunk is counted in exactly one row, so the rows add up to the total.
A group row shows what is exclusive to it: no archive of another group references these
chunks, so deleting all archives of that group would free them. Chunks used by several
groups are counted in the shared row, not against any single group.

source       = uncompressed source data size (each chunk counted once)
stored       = deduplicated size as stored in the repository (compressed)
compression  = stored / source (1.00 = not compressible)
unreferenced = referenced by no non-deleted archive; borg compact could free
               these. Their source size (n/a) is not known: it is only recorded
               in the archives referencing a chunk. Chunks of soft-deleted
               archives count as unreferenced (borg compact keeps them if the
               repository is damaged).

Deleting all projects archives would free only 127.78 kB: almost all of their data is also referenced by the home archives, so it is counted in the shared row. The 52.23 kB of unreferenced chunks belong to the deleted home archive; borg compact would free them.

In a repository shared by multiple machines that may use the same archive names, use --group-by name,host instead.

Size of one series and its hot spots:

$ borg analyze --match-archives home

Deduplicated size of the 3 considered archive(s)
===================================================================
Considered archives: 3 (of 8 in the repository)

                                  source        stored  compression
Deduplicated size of set:       50.74 MB      45.16 MB         0.89
Exclusive size of set:          45.41 MB      43.01 MB         0.95
Unreferenced chunks:                 n/a      52.23 kB          n/a

Unreferenced: 4 of 749 chunks in the repository index.

source       = uncompressed source data size (chunks shared within the set counted once)
stored       = deduplicated size as stored in the repository (compressed)
compression  = stored / source (1.00 = not compressible)
exclusive    = chunks referenced only by this set; would be freed by deleting the set
unreferenced = chunks referenced by no non-deleted archive; borg compact could free
               these. Their source size (n/a) is not known: it is only recorded in
               the archives referencing a chunk. Chunks of soft-deleted archives
               count as unreferenced (borg compact keeps them if the repo is damaged).

chunks added or removed by directory path
=========================================
home/user/Downloads: 30000000
home/user/.cache/thumbnails: 10357664
home/user/Documents/borg-docs: 200842
home/user/projects/borg: 141462

The exclusive size is smaller than the deduplicated size of the set because the projects archives also reference some of the home data.

The hot spots list the summed source size (in bytes) of the chunks added or removed between consecutive considered archives, per directory: here, a deleted 30 MB download and a thumbnail cache that changes all the time (a candidate for borg create --exclude).

As the hot spot analysis compares each considered archive with the previous one, select a single series (as above): comparing archives of different series would report most of their content as changed.

The usual archive filters select a subset of a series, e.g. its two most recent archives:

$ borg analyze --match-archives home --last 2

Use --json to process the numbers (raw byte values) further, e.g. with jq:

$ borg analyze --group-by name --json | jq -r '.by_group.groups[] | "\(.group.name): \(.stored_size)"'
home: 43013626
projects: 127775
etc: 46621