Merge pull request #4544 from ThomasWaldmann/improve-compact

small borg compact improvements, fixes #4522
This commit is contained in:
TW 2019-05-07 14:42:48 +02:00 committed by GitHub
commit fe2e9d77e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View File

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

View File

@ -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.
""")

View File

@ -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):