Skip to content

Instantly share code, notes, and snippets.

@haarts
Forked from shardnit/dump_bitcask_data.rb
Created March 19, 2012 15:20
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 haarts/2115997 to your computer and use it in GitHub Desktop.
Save haarts/2115997 to your computer and use it in GitHub Desktop.
Dump Riak Bitcask data locally
require 'rubygems'
require 'bitcask'
require 'bert'
require 'fileutils'
require 'json'
require 'time'
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
next if bucket.nil?
value = BERT.decode entry.value
next if value[-1] == []
begin
created_at = Time.parse(JSON.parse(value[-1])["created_at"])
rescue Exception => e
puts e.inspect
File.open('invalid_keys.txt', 'w') do |f|
f.puts key
end
next
end
bucket_dir = File.join(dump_dir, bucket)
FileUtils.mkdir_p(bucket_dir)
File.open(File.join(bucket_dir, created_at.strftime("%d-%m-%Y")), 'a') do |out|
out.write "#{key}\t#{value[-1]}\n"
end
end
end
end
source 'http://rubygems.org'
gem 'bitcask'
gem 'bert'
GEM
remote: http://rubygems.org/
specs:
bert (1.1.2)
bitcask (0.2.1)
PLATFORMS
ruby
DEPENDENCIES
bert
bitcask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment