Class: Backzilla::Entity::MySQL
- Inherits:
-
Backzilla::Entity
- Object
- Backzilla::Entity
- Backzilla::Entity::MySQL
- Includes:
- Backzilla::Executor
- Defined in:
- lib/backzilla/entity/my_sql.rb
Constant Summary
Constants inherited from Backzilla::Entity
Instance Attribute Summary
Attributes inherited from Backzilla::Entity
Instance Method Summary collapse
- #backup ⇒ Object
- #finalize_restore(options = {}) ⇒ Object
-
#initialize(name, options) ⇒ MySQL
constructor
A new instance of MySQL.
- #prepare_backup ⇒ Object
- #remove ⇒ Object
- #restore ⇒ Object
Methods included from Backzilla::Executor
Methods included from LoggerHelper
Constructor Details
#initialize(name, options) ⇒ MySQL
Returns a new instance of MySQL.
4 5 6 7 8 9 10 11 |
# File 'lib/backzilla/entity/my_sql.rb', line 4 def initialize(name, ) super(name) @database = ['database'] @mysql_options = { 'user' => ['user'], 'password' => ['password'], } end |
Instance Method Details
#backup ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/backzilla/entity/my_sql.rb', line 27 def backup prepare_backup backup_msg path = Pathname.new(BASE_PATH) + project.name + name Backzilla.store path, project.name, self.name FileUtils.rm_rf path end |
#finalize_restore(options = {}) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/backzilla/entity/my_sql.rb', line 36 def finalize_restore(={}) path = [:path] + "*.sql" Dir.glob(path).each do |dir| cmd = "mysql #{} #{@database} <"+dir execute cmd end FileUtils.rm_rf [:path] end |
#prepare_backup ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/backzilla/entity/my_sql.rb', line 13 def prepare_backup if @database.blank? fatal "Database name is blank" exit -1 end path = Pathname.new(BASE_PATH) + project.name + name FileUtils.mkdir_p path filename = path + "#{@database}.sql" cmd = "mysqldump #{} #{@database} > #{filename}" execute cmd filename end |
#remove ⇒ Object
56 57 58 59 |
# File 'lib/backzilla/entity/my_sql.rb', line 56 def remove Backzilla.remove @path, project.name, self.name @path end |
#restore ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/backzilla/entity/my_sql.rb', line 45 def restore filename = "" restore_msg path = Pathname.new(BASE_PATH) + project.name + name FileUtils.mkdir_p path filename = path + "#{@database}.sql" Backzilla.restore path, project.name, self.name finalize_restore(:path => path) end |