Last active
March 23, 2016 04:54
-
-
Save vmx/2338917129f02266e846 to your computer and use it in GitHub Desktop.
Dump the contents of a Couchbase vBucket into a directory where the keys are the filenames
This file contains hidden or 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 python2 | |
# Dump the contents of a vbucket file into a directory of the same name. The | |
# keys are the filenames, the value the file contents | |
import os | |
import sys | |
import couchstore | |
DECOMPRESS_DOC_BODIES = 1 | |
def callback(outdir, docinfo): | |
filename = os.path.join(outdir, docinfo.id) | |
print("writing {}".format(filename)) | |
with open(filename, 'w') as f: | |
contents = docinfo.getContents(DECOMPRESS_DOC_BODIES) | |
f.write(contents) | |
def usage(name): | |
print("usage: {} <filename>".format(name)) | |
return 1 | |
def main(argv=None): | |
if argv is None: | |
argv = sys.argv | |
if len(argv) != 2: | |
return usage(argv[0]) | |
vbucket_file = argv[1] | |
outdir = vbucket_file.split('.couch')[0] | |
try: | |
os.mkdir(outdir) | |
except OSError: | |
pass | |
db = couchstore.CouchStore(vbucket_file) | |
db.forEachDoc(None, None, lambda x: callback(outdir, x)) | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment