Class: WpBackup::Database
- Inherits:
-
Object
- Object
- WpBackup::Database
- Defined in:
- lib/wp_backup/database.rb
Instance Method Summary collapse
- #dump_to(file) ⇒ Object
-
#initialize(db_name, login, password) ⇒ Database
constructor
A new instance of Database.
- #restore_from(file) ⇒ Object
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, login, password) @db_name = db_name @login = 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 |