Class: Muck::Database
- Inherits:
-
Object
- Object
- Muck::Database
- Defined in:
- lib/muck/database.rb
Instance Method Summary collapse
- #archive_all ⇒ Object
- #backup ⇒ Object
- #backup_now? ⇒ Boolean
- #dump_command ⇒ Object
- #export_path ⇒ Object
- #hostname ⇒ Object
-
#initialize(server, properties) ⇒ Database
constructor
A new instance of Database.
- #last_backup_at ⇒ Object
- #manifest ⇒ Object
- #manifest_path ⇒ Object
- #name ⇒ Object
- #password ⇒ Object
- #save_manifest ⇒ Object
- #server ⇒ Object
- #username ⇒ Object
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_all ⇒ Object
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 |
#backup ⇒ Object
43 44 45 |
# File 'lib/muck/database.rb', line 43 def backup Muck::Backup.new(self).run end |
#backup_now? ⇒ 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_command ⇒ Object
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_path ⇒ Object
33 34 35 |
# File 'lib/muck/database.rb', line 33 def export_path @export_path ||= server.export_path.gsub(':database', self.name) end |
#hostname ⇒ Object
17 18 19 |
# File 'lib/muck/database.rb', line 17 def hostname @properties[:hostname] end |
#last_backup_at ⇒ Object
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 |
#manifest ⇒ Object
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_path ⇒ Object
47 48 49 |
# File 'lib/muck/database.rb', line 47 def manifest_path File.join(export_path, 'manifest.yml') end |
#name ⇒ Object
13 14 15 |
# File 'lib/muck/database.rb', line 13 def name @properties[:name] end |
#password ⇒ Object
25 26 27 |
# File 'lib/muck/database.rb', line 25 def password @properties[:password] end |
#save_manifest ⇒ Object
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 |
#server ⇒ Object
29 30 31 |
# File 'lib/muck/database.rb', line 29 def server @server end |
#username ⇒ Object
21 22 23 |
# File 'lib/muck/database.rb', line 21 def username @properties[:username] end |