Last active
August 23, 2023 18:02
-
-
Save enkore/14f7bd9f56d6cc17914a73345fd30fc4 to your computer and use it in GitHub Desktop.
Revisions
-
enkore revised this gist
Oct 5, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -34,7 +34,7 @@ def show_odd_cache_entries(_, args, repository, cache, manifest, key, count, col 'size': 1, 'csize': 2, }[column] contents = fun(count, cache.chunks.iteritems(), key=lambda k_r_s_c: k_r_s_c[1][index]) fmt = '%-64s %-16s %-16s %-16s' print(fmt % ('Object ID', 'refcount', 'size', 'csize')) for key, (refcount, size, csize) in contents: -
enkore revised this gist
Oct 5, 2016 . 1 changed file with 21 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,11 +4,15 @@ Usage: python show-odd-cache.py <repository> [<column to sort on>] [<number of entries to show>] Prints a list of the twenty cache entries with the highest reference count. This makes certain kinds of cache corruption (by bad drives, RAM etc) easy. Columns: **refcount**, size (payload size), csize (size in repo) Prepend a '-' to see the smallest values. Tested on Borg 1.0.x, Borg 1.1.x; works with remote repos. """ @@ -22,8 +26,15 @@ class XArchiver(Archiver): @with_repository(cache=True) def show_odd_cache_entries(_, args, repository, cache, manifest, key, count, column): fun = heapq.nsmallest if column.startswith('-') else heapq.nlargest column = column.strip('-') index = { 'refcount': 0, 'size': 1, 'csize': 2, }[column] contents = heapq.nlargest(count, cache.chunks.iteritems(), key=lambda k_r_s_c: k_r_s_c[1][index]) fmt = '%-64s %-16s %-16s %-16s' print(fmt % ('Object ID', 'refcount', 'size', 'csize')) for key, (refcount, size, csize) in contents: @@ -38,8 +49,11 @@ class Args: if __name__ == '__main__': try: column = sys.argv[2] except IndexError: column = 'refcount' try: count = int(sys.argv[3]) except IndexError: count = 20 XArchiver().show_odd_cache_entries(Args, count=count, column=column) -
enkore revised this gist
Oct 5, 2016 . 1 changed file with 24 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,29 @@ """ show-odd-cache.py ----------------- Usage: python show-odd-cache.py <repository> [<number of entries to show>] Prints a list of the twenty cache entries with the highest reference count. This makes certain kinds of cache corruption (by bad drives, RAM etc) easy. Tested on Borg 1.0.x, Borg 1.1.x; works with remote repos. """ import heapq import sys from binascii import hexlify from borg.archiver import Archiver, with_repository, UMASK_DEFAULT from borg.helpers import location_validator class XArchiver(Archiver): @with_repository(cache=True) def show_odd_cache_entries(_, args, repository, cache, manifest, key, count): contents = heapq.nlargest(count, cache.chunks.iteritems(), key=lambda k_r_s_c: k_r_s_c[1]) fmt = '%-64s %-16s %-16s %-16s' print(fmt % ('Object ID', 'refcount', 'size', 'csize')) for key, (refcount, size, csize) in contents: @@ -19,8 +32,14 @@ def show_odd_cache_entries(_, args, repository, cache, manifest, key): class Args: location = location_validator(archive=False)(sys.argv[1]) umask = UMASK_DEFAULT remote_path = 'borg' if __name__ == '__main__': try: count = int(sys.argv[2]) except: count = 20 XArchiver().show_odd_cache_entries(Args, count=count) -
enkore revised this gist
Oct 4, 2016 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ import heapq import sys from binascii import hexlify @@ -9,9 +10,7 @@ class XArchiver(Archiver): @with_repository(cache=True) def show_odd_cache_entries(_, args, repository, cache, manifest, key): contents = heapq.nlargest(20, cache.chunks.iteritems(), key=lambda k_r_s_c: k_r_s_c[1]) fmt = '%-64s %-16s %-16s %-16s' print(fmt % ('Object ID', 'refcount', 'size', 'csize')) for key, (refcount, size, csize) in contents: -
enkore created this gist
Oct 4, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ import sys from binascii import hexlify from borg.archiver import Archiver, with_repository from borg.helpers import location_validator class XArchiver(Archiver): @with_repository(cache=True) def show_odd_cache_entries(_, args, repository, cache, manifest, key): contents = list(cache.chunks.iteritems()) contents.sort(key=lambda k_r_s_c: k_r_s_c[1], reverse=True) contents = contents[:20] fmt = '%-64s %-16s %-16s %-16s' print(fmt % ('Object ID', 'refcount', 'size', 'csize')) for key, (refcount, size, csize) in contents: print(fmt % (hexlify(key).decode(), refcount, size, csize)) class Args: location = location_validator(archive=False)(sys.argv[1]) if __name__ == '__main__': XArchiver().show_odd_cache_entries(Args)