Skip to content

Instantly share code, notes, and snippets.

@gholt
Last active December 31, 2015 19:29
Show Gist options
  • Save gholt/8034056 to your computer and use it in GitHub Desktop.
Save gholt/8034056 to your computer and use it in GitHub Desktop.
"""
Script to find any old-style full urls x-container-sync-to settings.
Run as the user that Swift runs as and give the script one or more
container directories to scan, such as:
python find_old_style_container_sync_settings.py /srv/node/*/containers
It will output a line per find: account/container x-container-sync-to-value
Such as:
AUTH_test/test2 http://127.0.0.1/v1/a/c
Since there could be multiple replicas of the same container, you
probably want to collect all the output and then run it through: sort -u
"""
import os
import sys
import urllib
from swift.container.backend import ContainerBroker
if __name__ == '__main__':
if len(sys.argv) < 2:
sys.exit('''
Syntax: %s <path-to-containers-directory>
Be sure to run as the user that Swift runs as.
'''.strip() % os.path.basename(sys.argv[0]))
for path in sys.argv[1:]:
for root, dnames, fnames in os.walk(path):
for fname in fnames:
if fname.endswith('.db'):
broker = ContainerBroker(os.path.join(root, fname))
sync_to = broker.metadata.get('X-Container-Sync-To')
if sync_to and not sync_to[0].startswith('//'):
info = broker.get_info()
container = urllib.quote(
(info['account'] + '/' + info['container']).encode(
'utf8'))
sync_to = urllib.quote(
sync_to[0].encode('utf8'), safe='/:')
print container, sync_to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment