diff --git a/docs/usage/compact.rst b/docs/usage/compact.rst index f61375e0..2633d29e 100644 --- a/docs/usage/compact.rst +++ b/docs/usage/compact.rst @@ -7,9 +7,7 @@ Examples # compact segments and free repo disk space $ borg compact /path/to/repo - # same as above plus clean up 17byte commit-only segments, - # use this one time after upgrading borg (server) to 1.2+ - # to clean up the tiny segments files created by borg 1.1: + # same as above plus clean up 17byte commit-only segments $ borg compact --cleanup-commits /path/to/repo diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 5a72fcc1..03f91944 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -2777,12 +2777,20 @@ class Archiver: This command frees repository space by compacting segments. Use this regularly to avoid running out of space - you do not need to use this - after each borg command though. + after each borg command though. It is especially useful after deleting archives, + because only compaction will really free repository space. borg compact does not need a key, so it is possible to invoke it from the client or also from the server. - Depending on the amount of segments that need compaction, it may take a while. + Depending on the amount of segments that need compaction, it may take a while, + so consider using the ``--progress`` option. + + When using ``--verbose``, borg will output an estimate of the freed space. + + After upgrading borg (server) to 1.2+, you can use ``borg compact --cleanup-commits`` + to clean up the numerous 17byte commit-only segments that borg 1.1 did not clean up + due to a bug. It is enough to do that once per repository. See :ref:`separate_compaction` in Additional Notes for more details. """) diff --git a/src/borg/repository.py b/src/borg/repository.py index 18995af9..e53cec6d 100644 --- a/src/borg/repository.py +++ b/src/borg/repository.py @@ -695,6 +695,7 @@ class Repository: if not self.compact: logger.debug('nothing to do: compact empty') return + freed_space = 0 index_transaction_id = self.get_index_transaction_id() segments = self.segments unused = [] # list of segments, that are not used anymore @@ -734,6 +735,7 @@ class Repository: segment, freeable_ratio * 100.0, freeable_space) pi.show() continue + freed_space += freeable_space # this is what we THINK we can free segments.setdefault(segment, 0) logger.debug('compacting segment %d with usage count %d (freeable: %2.2f%% [%d bytes])', segment, segments[segment], freeable_ratio * 100.0, freeable_space) @@ -814,6 +816,7 @@ class Repository: pi.show() pi.finish() complete_xfer(intermediate=False) + logger.info('compaction freed about %s repository space.', format_file_size(freed_space)) logger.debug('compaction completed.') def replay_segments(self, index_transaction_id, segments_transaction_id):