Class: WpBackup::Database

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

Instance Method Summary collapse

Constructor Details

#initialize(db_name, login, password) ⇒ Database

Returns a new instance of Database.



4
5
6
7
8
# File 'lib/wp_backup/database.rb', line 4

def initialize(db_name, , password)
  @db_name = db_name
  @login = 
  @password = password
end

Instance Method Details

#dump_to(file) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/wp_backup/database.rb', line 10

def dump_to(file)
  cmd = "mysqldump --opt --skip-add-locks -u#{@login} "
  cmd += "-p'#{@password}' " unless @password.nil? || @password.length == 0
  cmd += " #{@db_name} > #{file}"
  result = system(cmd)
  raise("ERROR: mysqldump failed (#{$?})") unless result
end

#restore_from(file) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/wp_backup/database.rb', line 18

def restore_from(file)
  if File.exists?(file)
    cmd = "mysql -u#{@login} "
    cmd += "-p'#{@password}' " unless @password.nil? || @password.length == 0
    cmd += " #{@db_name} < #{file}"
    system(cmd)
  end
end