Skip to content

Instantly share code, notes, and snippets.

@shardnit
Created March 2, 2012 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shardnit/1957817 to your computer and use it in GitHub Desktop.
Save shardnit/1957817 to your computer and use it in GitHub Desktop.
Dump Riak Bitcask data locally
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