Class: Backarch::Config
- Inherits:
-
Object
- Object
- Backarch::Config
- Extended by:
- GLI::App
- Defined in:
- lib/backarch/config.rb
Constant Summary collapse
- DATE_FORMAT =
'%Y%m%d'
Class Attribute Summary collapse
-
.opts ⇒ Object
Returns the value of attribute opts.
-
.program_name ⇒ Object
Returns the value of attribute program_name.
-
.target_app ⇒ Object
Returns the value of attribute target_app.
Class Method Summary collapse
- .cassandra_version ⇒ Object
- .compress ⇒ Object
- .config ⇒ Object
- .date ⇒ Object
- .init ⇒ Object
- .init_aws ⇒ Object
- .input ⇒ Object
- .link_prior ⇒ Object
- .nodetool ⇒ Object
- .output ⇒ Object
- .snapshot_dir(offset = 0) ⇒ Object
Class Attribute Details
.opts ⇒ Object
Returns the value of attribute opts.
10 11 12 |
# File 'lib/backarch/config.rb', line 10 def opts @opts end |
.program_name ⇒ Object
Returns the value of attribute program_name.
8 9 10 |
# File 'lib/backarch/config.rb', line 8 def program_name @program_name end |
.target_app ⇒ Object
Returns the value of attribute target_app.
9 10 11 |
# File 'lib/backarch/config.rb', line 9 def target_app @target_app end |
Class Method Details
.cassandra_version ⇒ Object
123 124 125 |
# File 'lib/backarch/config.rb', line 123 def cassandra_version @opts[:cassandra_version] end |
.compress ⇒ Object
107 108 109 |
# File 'lib/backarch/config.rb', line 107 def compress @opts[:no_compress] ? false : true end |
.config ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/backarch/config.rb', line 111 def config @opts[:config] ||= case @target_app when :elasticsearch then '/etc/chef/elasticsearch_archive.yaml' when :cassandra then '/etc/chef/cassandra_archive.yaml' end YAML.load(File.read(@opts[:config])) end |
.date ⇒ Object
119 120 121 |
# File 'lib/backarch/config.rb', line 119 def date @opts[:date] ||= Date.today.strftime('%Y%m%d') end |
.init ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/backarch/config.rb', line 14 def init @program_name = $0 program_desc 'Snapshot and archival suite for Cassandra and ElasticSearch' version Backarch::VERSION desc 'The Cassandra, ElasticSearch, or tar data directory' flag :i, :input desc "Configuration file location (default: /etc/chef/elasticsearch_archive.yaml)" flag :c, :config desc "The date for the archive (defaults to today)" flag :d, :date desc "Log level (info, debug...)" default_value 'info' flag :l, :log_level desc "The snapshot or tar output location" flag :o, :output desc "Prior snapshot directory to hard link to with rsync" flag :p, :link_prior desc 'Disable compression of archive' switch :Z, :no_compress desc 'Full path to the nodetool binary' flag(:n, :nodetool) desc 'The version of the cassandra application (required for pre 1.0 versions)' flag(:V, :cassandra_version) command(:cassandra) do |cmd| cmd.action do |global_opts, opts, args| @target_app = :cassandra init_aws case args.first when 'snapshot' Snapshot::Cassandra.run when 'archive' Archive.run end end end command(:elasticsearch) do |cmd| cmd.action do |global_opts, opts, args| @target_app = :elasticsearch init_aws case args.first when 'snapshot' Snapshot::Elasticsearch.run when 'archive' Archive.run when 'restore' ElasticsearchRestoration.run end end end command(:tar) do |cmd| cmd.action do |global_opts, opts, args| @target_app = :tar case args.first when 'extract' TarExtracter.run end end end pre do |global_opts, command, opts, args| @opts = global_opts.merge(opts) LOG.level = LOG_LEVELS[@opts[:log_level]] end run(ARGV) end |
.init_aws ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/backarch/config.rb', line 97 def init_aws AWS.config \ :access_key_id => config['aws']["aws_access_key_id"], :secret_access_key => config['aws']["aws_secret_access_key"], :ssl_verify_peer => false, :http_open_timeout => 2, :http_read_timeout => 2, :http_idle_timeout => 5 end |
.input ⇒ Object
131 132 133 |
# File 'lib/backarch/config.rb', line 131 def input @opts[:input].gsub(%r{/\Z}, '') if @opts[:input] end |
.link_prior ⇒ Object
139 140 141 |
# File 'lib/backarch/config.rb', line 139 def link_prior @opts[:link_prior] ||= (1..30).map { |i| snapshot_dir(i * -1) }.select { |dir| Dir.exists? dir }.first end |
.nodetool ⇒ Object
135 136 137 |
# File 'lib/backarch/config.rb', line 135 def nodetool @opts[:nodetool] ||= '/usr/lib/cassandra/bin/nodetool' end |
.output ⇒ Object
127 128 129 |
# File 'lib/backarch/config.rb', line 127 def output @opts[:output].gsub(%r{/\Z}, '') if @opts[:output] end |
.snapshot_dir(offset = 0) ⇒ Object
143 144 145 |
# File 'lib/backarch/config.rb', line 143 def snapshot_dir offset=0 "#{Config.output}/full/#{(Date.strptime(date, DATE_FORMAT) + offset).strftime(DATE_FORMAT)}" end |