Created
July 28, 2016 21:49
-
-
Save textshell/ac8486af3fc08b52278df9c672732656 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
{[0]} path/to/repo | |
Show object summary in a borg repository. | |
That is, amount of objects currently still without a delete, | |
amount of objects that are deleted and amount of delete markers | |
""" | |
import sys | |
from borg.repository import Repository, TAG_PUT, TAG_DELETE | |
if len(sys.argv) != 2: | |
print(__doc__.format(sys.argv)) | |
sys.exit(0) | |
print("Pointed at repo:", sys.argv[1]) | |
repo = Repository(sys.argv[1], create=False, exclusive=True, lock_wait=None, lock=True, append_only=False) | |
with repo as r: | |
r.index = r.open_index(r.get_transaction_id(), False) | |
objs_free = 0 | |
objs_used = 0 | |
objs_delete = 0 | |
for i, (segment, filename) in enumerate(r.io.segment_iterator()): | |
segment_size = r.io.segment_size(segment) | |
for tag, key, offset, data in r.io.iter_objects(segment, include_data=False): | |
if tag == TAG_PUT and r.index.get(key, (-1, -1)) == (segment, offset): | |
objs_used += 1 | |
elif tag == TAG_PUT: | |
objs_free += 1 | |
elif tag == TAG_DELETE: | |
objs_delete += 1 | |
print("chunks: used ", objs_used, " free ", objs_free, " delete ", objs_delete) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment