class Snapshooter::Datastore::Mysql

Public Class Methods

new(options={}) click to toggle source
# File lib/snapshooter/datastore/mysql.rb, line 6
def initialize(options={})
  @options = options
end

Public Instance Methods

filename() click to toggle source
# File lib/snapshooter/datastore/mysql.rb, line 18
def filename
  "#{id}.sql"
end
restore(file) click to toggle source
# File lib/snapshooter/datastore/mysql.rb, line 14
def restore(file)
  `mysql #{mysql_options} #{@options[:database]} < #{file}`
end
snapshot(tmp_file) click to toggle source
# File lib/snapshooter/datastore/mysql.rb, line 10
def snapshot(tmp_file)
  `mysqldump #{mysqldump_options} #{@options[:database]} > #{tmp_file}`
end

Private Instance Methods

id() click to toggle source
# File lib/snapshooter/datastore/mysql.rb, line 24
def id
  Digest::MD5.hexdigest(@options.to_s)
end
mysql_options() click to toggle source
# File lib/snapshooter/datastore/mysql.rb, line 28
def mysql_options
  options = []
  options << "-u#{@options[:user]}"     if @options[:user]
  options << "-p#{@options[:password]}" if @options[:password]
  options << "-h#{@options[:host]}"     if @options[:host]

  options.join(" ")
end
mysqldump_options() click to toggle source
# File lib/snapshooter/datastore/mysql.rb, line 37
def mysqldump_options
  ["--single-transaction", mysql_options].join(" ")
end