class Stratocumulus::Database
Public Class Methods
backends()
click to toggle source
# File lib/stratocumulus/database.rb, line 16 def self.backends { "psql" => PostgreSQL, "mysql" => MySQL, "etcd" => ETCD, } end
build(options = {})
click to toggle source
# File lib/stratocumulus/database.rb, line 10 def self.build(options = {}) backend_class = backends[options["type"]] fail "#{options["type"]} is not a supported database" unless backend_class backend_class.new(options) end
new(options = {})
click to toggle source
# File lib/stratocumulus/database.rb, line 24 def initialize(options = {}) check_dependencies @username = options["username"] @password = options["password"] @name = options["name"] fail "database name not specified" unless @name @host = options["host"] @port = options["port"] end
Public Instance Methods
cleanup()
click to toggle source
# File lib/stratocumulus/database.rb, line 52 def cleanup # NOOP end
dependencies()
click to toggle source
# File lib/stratocumulus/database.rb, line 48 def dependencies ["gzip"] end
dump()
click to toggle source
# File lib/stratocumulus/database.rb, line 34 def dump @dump ||= PipeIO.popen("bash -c '#{pipefail} #{command} | gzip'") end
filename()
click to toggle source
# File lib/stratocumulus/database.rb, line 38 def filename @name + "/" + file end
success?()
click to toggle source
# File lib/stratocumulus/database.rb, line 42 def success? dump.read dump.close $CHILD_STATUS.success? end
Private Instance Methods
check_dependencies()
click to toggle source
# File lib/stratocumulus/database.rb, line 58 def check_dependencies dependencies.each do |cmd| fail "#{cmd} not available" unless system("which #{cmd} >/dev/null") end end
file()
click to toggle source
# File lib/stratocumulus/database.rb, line 64 def file @file ||= Time.now.utc.strftime("#{@name}.%Y%m%d%H%M#{suffix}") end
pipefail()
click to toggle source
# File lib/stratocumulus/database.rb, line 72 def pipefail "set -o pipefail;" end
socket?()
click to toggle source
# File lib/stratocumulus/database.rb, line 76 def socket? !@host && !@port end
suffix()
click to toggle source
# File lib/stratocumulus/database.rb, line 68 def suffix ".sql.gz" end