Class: Muck::Database

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

Instance Method Summary collapse

Constructor Details

#initialize(server, properties) ⇒ Database

Returns a new instance of Database.



8
9
10
11
# File 'lib/muck/database.rb', line 8

def initialize(server, properties)
  @server = server
  @properties = properties
end

Instance Method Details

#archive_allObject



37
38
39
40
41
# File 'lib/muck/database.rb', line 37

def archive_all
  @server.retention.each do |name, maximum|
    Muck::Archive.new(self, name, maximum).run
  end
end

#backupObject



43
44
45
# File 'lib/muck/database.rb', line 43

def backup
  Muck::Backup.new(self).run
end

#backup_now?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/muck/database.rb', line 72

def backup_now?
  last_backup_at.nil? || last_backup_at <= Time.now - (@server.frequency * 60)
end

#dump_commandObject



59
60
61
62
# File 'lib/muck/database.rb', line 59

def dump_command
  password_opt = password ? "-p#{password}" : ""
  "mysqldump -q --single-transaction -h #{hostname} -u #{username} #{password_opt} #{name}"
end

#export_pathObject



33
34
35
# File 'lib/muck/database.rb', line 33

def export_path
  @export_path ||= server.export_path.gsub(':database', self.name)
end

#hostnameObject



17
18
19
# File 'lib/muck/database.rb', line 17

def hostname
  @properties[:hostname]
end

#last_backup_atObject



64
65
66
67
68
69
70
# File 'lib/muck/database.rb', line 64

def last_backup_at
  if last_backup = manifest[:backups].last
    Time.at(last_backup[:timestamp])
  else
    nil
  end
end

#manifestObject



51
52
53
# File 'lib/muck/database.rb', line 51

def manifest
  @manifest ||= File.exist?(manifest_path) ? YAML.load_file(manifest_path) : {:backups => []}
end

#manifest_pathObject



47
48
49
# File 'lib/muck/database.rb', line 47

def manifest_path
  File.join(export_path, 'manifest.yml')
end

#nameObject



13
14
15
# File 'lib/muck/database.rb', line 13

def name
  @properties[:name]
end

#passwordObject



25
26
27
# File 'lib/muck/database.rb', line 25

def password
  @properties[:password]
end

#save_manifestObject



55
56
57
# File 'lib/muck/database.rb', line 55

def save_manifest
  File.open(manifest_path, 'w') { |f| f.write(manifest.to_yaml) }
end

#serverObject



29
30
31
# File 'lib/muck/database.rb', line 29

def server
  @server
end

#usernameObject



21
22
23
# File 'lib/muck/database.rb', line 21

def username
  @properties[:username]
end