Class: Eedb

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

Class Method Summary collapse

Class Method Details

.export(server = :local) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/eedb.rb', line 52

def self.export(server = :local)
  other_server = server == :local ? :remote : :local
  
  log "*** Starting dump..."

  log "*   Dumping #{server}..."
  Mysql.dump(server)

  print "-   Do you want to push this into the #{other_server} server? (Y/n): "
  answer = STDIN.gets.chomp

  if answer == "Y"
    print "-   Do you want to backup the #{other_server} DB? (Y/n): "
    answer2 = STDIN.gets.chomp

    if answer2 == "Y"
      log "*   Dumping #{other_server} as backup..."
      Mysql.dump(other_server, :backup)
    end
    
    log "**  Cleanup #{server}..."
    cleaned_file = Mysql.cleanup_file(server)
    
    log "*** Pushing #{server} cleaned file to #{other_server}..."
    Mysql.import(cleaned_file => other_server)
  end

  log "*** Done."
end

.importObject



82
83
84
# File 'lib/eedb.rb', line 82

def self.import
  export(:remote)
end

.log(what) ⇒ Object



86
87
88
# File 'lib/eedb.rb', line 86

def self.log(what)
  puts what
end

.rollback(which) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/eedb.rb', line 38

def self.rollback(which)
  backup = File.expand_path(Dir["tmp/#{which}-dump-*.sql.backup"].last)
  
  print "-   Are you sure you want to rollback the #{which} DB? (Y/n): "
  answer = STDIN.gets.chomp

  if answer == "Y"
    log "*** Rolling back #{which} using #{backup}..."
    Mysql.import(backup => which)
  end

  log "*** Done."
end