Class: Savior::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/savior/database.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Database

Returns a new instance of Database.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/savior/database.rb', line 3

def initialize(options = {})
  default_options = {
    :user          => nil,
    :password      => nil,
    :host          => "localhost",
    :port          => "3306",
    :database_name => nil,
  }
  options        = default_options.merge(options)
  @user          = options[:user]
  @password      = options[:password]
  @host          = options[:host]
  @port          = options[:port]
  @database_name = options[:database_name]
end

Instance Method Details

#create_snapshotObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/savior/database.rb', line 19

def create_snapshot
  db_snapshot_file = set_db_snapshot_file_name
  file = File.open(db_snapshot_file, "w+")
  IO.popen("mysqldump #{mysql_command_line_options}","r+") do |pipe|
    pipe.close_write
    while (line = pipe.gets)
      file.puts line
    end
  end
  file.close
  db_snapshot_file
end