Skip to content

Instantly share code, notes, and snippets.

@cschwede
Created April 6, 2023 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cschwede/6ea6a6593882d8982468e698a90a0ce3 to your computer and use it in GitHub Desktop.
Save cschwede/6ea6a6593882d8982468e698a90a0ce3 to your computer and use it in GitHub Desktop.
Sample code to iterate over OpenStack Swift container DB files
#!/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