Created
April 6, 2023 14:31
-
-
Save cschwede/6ea6a6593882d8982468e698a90a0ce3 to your computer and use it in GitHub Desktop.
Sample code to iterate over OpenStack Swift container DB files
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
#!/usr/bin/env python | |
from swift.common.utils import audit_location_generator | |
from swift.container.backend import ContainerBroker | |
if __name__ == '__main__': | |
locations = audit_location_generator('/srv/node', 'containers', '.db') | |
for path, _, _ in locations: | |
try: | |
broker = ContainerBroker(path) | |
if not broker.is_deleted(): | |
info = broker.get_info() | |
account = info.get('account') | |
container = info.get('container') | |
total_bytes = info.get('reported_bytes_used') | |
for obj in broker.get_objects(): | |
deleted = obj.get('deleted') | |
if not deleted: | |
obj_name = obj.get('name') | |
size = obj.get('size') | |
created = obj.get('created_at') | |
print(account, container, total_bytes, obj_name, size, created) | |
except Exception as err: | |
print(err) | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment