borg-compact(1)
πΈ borg-compact π
okay bestie, say hi to borg-compact, a page from the borg backup tool manual. she's the one who takes out the trash ποΈβ¨
β¨ NAME β¨
borg-compact β Collects garbage in the repository. literally her whole job, no cap π§Ή
π SYNOPSIS π
borg [common options] compact [options]
π DESCRIPTION π
Free repository space by deleting unused chunks. that's it, that's the vibe π¦
borg compact analyzes all existing archives to determine which repository objects are actually used (referenced). then β and this is the moment β it deletes all unused objects from the repository to free space. main character behaviour fr fr π
so likeβ¦ where do these unused objects even come from?? π€
Unused objects may result from:
- use of
borg deleteorborg prune - interrupted backups (consider retrying the backup before running
compact) π - backups of source files that encountered an I/O error mid-transfer and were skipped π
- corruption of the repository (e.g., the archives directory lost entries; see notes below) π
borg compact reclaims objects the chunk index knows about, plus redundant copies of indexed chunks (e.g. written by concurrent backups) that it finds while rewriting a pack. Other bytes no index entry covers, such as packs left behind by a backup that crashed before recording its objects, are re-indexed by borg check --repair and reclaimed by the next borg compact. β¨
borg compact does not rewrite or merge packs that borg check recorded as corrupt and warns about them. borg check --repair --verify-data deletes the corrupt chunks by rewriting their packs. It does not remove damage outside any chunk (e.g. bytes appended to a pack): a pack with such damage and no corrupt chunk stays recorded corrupt and borg compact warns about it on every run, a pack that also has a corrupt chunk is rewritten with that damage copied into the new pack (refs #10026). π«Ά
You usually do not want to run borg compact after every write operation, but either regularly (e.g., once a month, possibly together with borg check) or when disk space needs to be freed. lowkey just do it on a schedule π
the cost of compacting (a lil gatekeeping, respectfully) πͺ
Compacting anything rewrites the whole chunk index and invalidates every client's cached copy of it, so borg compact only acts when the gain is worth that cost:
- All-packs gate: it drops or rewrites packs only when the space they would free reaches
--thresholddivided by 5 percent (2% at the default threshold) of the total pack size. Below that floor it leaves the repository (and the chunk index) untouched. Use--threshold 0to disable the gate and always compact. periodt. - Tiny-pack merging: incremental backups tend to leave one small, fully-used pack per run.
borg compactcombines such tiny packs into larger ones, but only once their combined size is large enough to fill at least one full-size pack, so a merge always produces a pack that will not be a merge candidate again. queen of efficiency π
β οΈ Important: β οΈ
After compacting, it is no longer possible to use borg undelete to recover previously soft-deleted archives. so likeβ¦ be sure, bestie π
borg compact might also delete data from archives that were "lost" due to archives directory corruption. Such archives could potentially be restored with borg check --find-lost-archives [--repair], which is slow. You therefore might not want to do that unless there are signs of lost archives (e.g., when seeing fatal errors when creating backups or when archives are missing in borg repo-list). ngl, only go looking if something's actually sus π
With --stats, borg additionally reports the on-disk size of the pack files before and after compaction (the reported compression factor is based on that size). cute numbers, love that for us π
β OPTIONS β
See borg-common(1) for common options of Borg commands. yes bestie, go read that one too, iykyk π«Ά
π options π
-n,--dry-runβ do not change the repository, just show what compact would free. window shopping, no spending πΈ-s,--statsβ print repository size statistics π--threshold PERCENTβ rewrite a pack when at least PERCENT of its bytes are unused; also gates whether to compact at all (see the all-packs gate above),0disables that gate (default:10) ποΈ
π¦ EXAMPLES π¦
# Free repository disk space by deleting unused chunks (rewriting packs as needed)
$ borg compact
look at her go β¨
π SEE ALSO π
π Author π
The Borg Collective π (a whole collective, very slay of them)
okay that's the whole page bestie, mwah π this was borg-compact(1), from the borg backup tool, dated 2026-10-07 β go free up that disk space, you got this π«Άβ¨π
π¦ where this page comes from
- ubuntu stonking: borgbackup2 2.0.0b25-4 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms