Class: Backzilla::Entity::MySQL

Inherits:
Backzilla::Entity show all
Includes:
Backzilla::Executor
Defined in:
lib/backzilla/entity/my_sql.rb

Constant Summary

Constants inherited from Backzilla::Entity

BASE_PATH

Instance Attribute Summary

Attributes inherited from Backzilla::Entity

#name, #project

Instance Method Summary collapse

Methods included from Backzilla::Executor

#execute

Methods included from LoggerHelper

#debug

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, options)
  super(name)
  @database = options['database']
  @mysql_options = {
    'user' => options['user'],
    'password' => options['password'],
  }
end

Instance Method Details

#backupObject



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(options={})
  path = options[:path] + "*.sql"
  Dir.glob(path).each do |dir|
    cmd = "mysql #{mysql_options} #{@database} <"+dir
    execute cmd
  end
  FileUtils.rm_rf options[:path]
end

#prepare_backupObject



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 #{mysql_options} #{@database} > #{filename}"
  execute cmd
  filename
end

#removeObject



56
57
58
59
# File 'lib/backzilla/entity/my_sql.rb', line 56

def remove
  Backzilla.remove @path, project.name, self.name
  @path
end

#restoreObject



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