Created
March 2, 2012 11:13
-
-
Save shardnit/1957817 to your computer and use it in GitHub Desktop.
Dump Riak Bitcask data locally
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
require 'rubygems' | |
require 'bitcask' | |
require 'bert' | |
require 'fileutils' | |
require 'json' | |
bitcask_dir = '/home/nitish/downloads/riak/rel/riak/data/bitcask/' | |
dump_dir = '/home/nitish/bitcask_dump/' | |
Dir.entries(bitcask_dir).each do |bitcask_file| | |
next if bitcask_file =~ /\A\./ | |
b = Bitcask.new File.join(bitcask_dir, bitcask_file) | |
b.data_files.each do |data_file| | |
data_file.each do |entry| | |
next if entry.value == Bitcask::TOMBSTONE | |
bucket, key = BERT.decode entry.key | |
value = BERT.decode entry.value | |
bucket_dir = File.join(dump_dir, bucket) | |
FileUtils.mkdir_p(bucket_dir) | |
File.open(File.join(bucket_dir,bitcask_file), 'a+') do |out| | |
#out.write value.to_json | |
out.write "#{key}\t#{value[-1]}\n" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment