cassandra_backup 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ = CassandraBackup
2
+
3
+ CassandraBackup is a command line tool for dumping and restoring a Cassandra column family.
4
+
5
+ == Dumping a Keyspace
6
+
7
+ Run cassandra_dump, specifying the keyspace:
8
+
9
+ cassandra_dump depot_production > backup.json
10
+
11
+ == Restoring a Keyspace
12
+
13
+ Run cassandra_import, specifying the keyspace:
14
+
15
+ cassandra_import depot_production < backup.json
16
+
17
+ == Options
18
+
19
+ --servers:: A comma delimited list of servers. Defaults to 127.0.0.1:9160. (--servers 127.0.0.14:9169,127.0.1.19:9100)
20
+ --version:: Set cassandra version. Defaults to 1.0. (--version 0.6)
21
+ --columns:: The column families to dump. Defaults to all. (--columns Widgets --columns People)
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('../../lib/cassandra_backup', __FILE__)
4
+ CassandraBackup::Dumper.run!
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('../../lib/cassandra_backup', __FILE__)
4
+ CassandraBackup::Importer.run!
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'cassandra_backup'
5
+ s.version = '0.0.1'
6
+ s.description = 'Cassandra Backup'
7
+ s.summary = 'Cassandra Backup'
8
+ s.authors = ['Infogroup']
9
+ s.email = 'gems@gotime.com'
10
+ s.homepage = 'http://github.com/data-axle/cassandra_backup'
11
+
12
+ s.required_ruby_version = '>= 1.8.7'
13
+ s.required_rubygems_version = '>= 1.8.0'
14
+ s.executables = ['cassandra_dump', 'cassandra_import']
15
+ s.extra_rdoc_files = ['README.rdoc']
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test}/*`.split("\n")
18
+
19
+ s.add_runtime_dependency('mcmire-cassandra', ">= 0.12.3")
20
+ s.add_runtime_dependency('yajl-ruby')
21
+ s.add_development_dependency('bundler')
22
+ end
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+ Bundler.require
3
+
4
+ require 'yajl'
5
+
6
+ require 'cassandra_backup/dumper'
7
+ require 'cassandra_backup/importer'
@@ -0,0 +1,30 @@
1
+ require 'cassandra_backup/command'
2
+
3
+ module CassandraBackup
4
+ class BackupProcess
5
+ def self.run!
6
+ new(CassandraBackup::Command.new(ARGV)).run
7
+ end
8
+
9
+ attr_reader :command
10
+ def initialize(command)
11
+ @command = command
12
+ end
13
+
14
+ def run
15
+ raise "inheriting class must implement"
16
+ end
17
+
18
+ def connection
19
+ @connection ||= Cassandra.new(command.keyspace, command.servers)
20
+ end
21
+
22
+ def input_io
23
+ $stdin
24
+ end
25
+
26
+ def output_io
27
+ $stdout
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,60 @@
1
+ module CassandraBackup
2
+ class Command
3
+
4
+ attr_accessor :options
5
+ def initialize(args)
6
+ self.options = {}
7
+
8
+ if args.first
9
+ options[:keyspace] = args.first
10
+ else
11
+ args.push '-h'
12
+ end
13
+
14
+ OptionParser.new do |opts|
15
+ opts.banner = "Usage: keyspace [options]"
16
+ opts.on('-s', '--servers SERVERS', 'Set server list. Default is 127.0.0.1:9160.') do |v|
17
+ options[:servers] = v.split(/\s|,/)
18
+ end
19
+ opts.on('-v', '--version VERSION', 'Set cassandra version. Default is 1.0.') do |v|
20
+ options[:version] = v
21
+ end
22
+ opts.on('-c', '--columns Columns', 'Set column families. Defaults to all') do |v|
23
+ (options[:columns] ||= []).concat v.split(/\s|,/)
24
+ end
25
+ opts.on('-h', 'Show this help message.') do
26
+ $stdout.puts opts; exit
27
+ end
28
+ opts.parse!(args)
29
+ end
30
+
31
+ require required_version
32
+ end
33
+
34
+ def keyspace
35
+ options[:keyspace]
36
+ end
37
+
38
+ def servers
39
+ if options[:servers]
40
+ options[:servers]
41
+ else
42
+ ['127.0.0.1:9160']
43
+ end
44
+ end
45
+
46
+ def columns
47
+ if options[:columns]
48
+ options[:columns]
49
+ end
50
+ end
51
+
52
+ def required_version
53
+ if options[:version]
54
+ "cassandra/#{options[:version]}"
55
+ else
56
+ "cassandra/1.0"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,26 @@
1
+ require 'cassandra_backup/backup_process'
2
+
3
+ module CassandraBackup
4
+ class Dumper < BackupProcess
5
+ def run
6
+ column_family_names.each do |column_family|
7
+ connection.each(column_family) do |key, attributes|
8
+ output_io.puts encoder.encode([column_family, key, attributes])
9
+ end
10
+ end
11
+ end
12
+
13
+ private
14
+ def column_family_names
15
+ if command.columns
16
+ command.columns
17
+ else
18
+ connection.column_families.keys - ['schema_migrations']
19
+ end
20
+ end
21
+
22
+ def encoder
23
+ @encoder ||= Yajl::Encoder.new
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ require 'cassandra_backup/backup_process'
2
+
3
+ module CassandraBackup
4
+ class Importer < BackupProcess
5
+ def run
6
+ parser.parse(input_io) do |column_family, key, attributes|
7
+ p "inserting"
8
+ connection.insert column_family, key, attributes
9
+ end
10
+ end
11
+
12
+ private
13
+ def parser
14
+ @parser ||= Yajl::Parser.new
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cassandra_backup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Infogroup
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mcmire-cassandra
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.12.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.12.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: yajl-ruby
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Cassandra Backup
63
+ email: gems@gotime.com
64
+ executables:
65
+ - cassandra_dump
66
+ - cassandra_import
67
+ extensions: []
68
+ extra_rdoc_files:
69
+ - README.rdoc
70
+ files:
71
+ - .gitignore
72
+ - Gemfile
73
+ - README.rdoc
74
+ - bin/cassandra_dump
75
+ - bin/cassandra_import
76
+ - cassandra_backup.gemspec
77
+ - lib/cassandra_backup.rb
78
+ - lib/cassandra_backup/backup_process.rb
79
+ - lib/cassandra_backup/command.rb
80
+ - lib/cassandra_backup/dumper.rb
81
+ - lib/cassandra_backup/importer.rb
82
+ homepage: http://github.com/data-axle/cassandra_backup
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.8.7
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: 1.8.0
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.24
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Cassandra Backup
106
+ test_files: []