class Muck::Database

Public Class Methods

new(server, properties) click to toggle source
# File lib/muck/database.rb, line 8
def initialize(server, properties)
  @server = server
  @properties = properties
end

Public Instance Methods

archive_all() click to toggle source
# 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
backup() click to toggle source
# File lib/muck/database.rb, line 43
def backup
  Muck::Backup.new(self).run
end
backup_now?() click to toggle source
# File lib/muck/database.rb, line 72
def backup_now?
  last_backup_at.nil? || last_backup_at <= Time.now - (@server.frequency * 60)
end
dump_command() click to toggle source
# 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_path() click to toggle source
# File lib/muck/database.rb, line 33
def export_path
  @export_path ||= server.export_path.gsub(':database', self.name)
end
hostname() click to toggle source
# File lib/muck/database.rb, line 17
def hostname
  @properties[:hostname]
end
last_backup_at() click to toggle source
# 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
manifest() click to toggle source
# File lib/muck/database.rb, line 51
def manifest
  @manifest ||= File.exist?(manifest_path) ? YAML.load_file(manifest_path) : {:backups => []}
end
manifest_path() click to toggle source
# File lib/muck/database.rb, line 47
def manifest_path
  File.join(export_path, 'manifest.yml')
end
name() click to toggle source
# File lib/muck/database.rb, line 13
def name
  @properties[:name]
end
password() click to toggle source
# File lib/muck/database.rb, line 25
def password
  @properties[:password]
end
save_manifest() click to toggle source
# File lib/muck/database.rb, line 55
def save_manifest
  File.open(manifest_path, 'w') { |f| f.write(manifest.to_yaml) }
end
server() click to toggle source
# File lib/muck/database.rb, line 29
def server
  @server
end
username() click to toggle source
# File lib/muck/database.rb, line 21
def username
  @properties[:username]
end