Class: Pgchief::Database::Backups
- Inherits:
-
Object
- Object
- Pgchief::Database::Backups
- Extended by:
- Forwardable
- Defined in:
- lib/pgchief/database/backups.rb
Overview
Get a list of all backups for a given database
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Class Method Summary collapse
Instance Method Summary collapse
- #for ⇒ Object
-
#initialize(database, remote:) ⇒ Backups
constructor
A new instance of Backups.
- #local_backups ⇒ Object
- #remote_backups ⇒ Object
Constructor Details
#initialize(database, remote:) ⇒ Backups
Returns a new instance of Backups.
19 20 21 22 |
# File 'lib/pgchief/database/backups.rb', line 19 def initialize(database, remote:) @database = database @remote = remote end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
17 18 19 |
# File 'lib/pgchief/database/backups.rb', line 17 def database @database end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
17 18 19 |
# File 'lib/pgchief/database/backups.rb', line 17 def remote @remote end |
Class Method Details
.for(database, remote:) ⇒ Object
13 14 15 |
# File 'lib/pgchief/database/backups.rb', line 13 def self.for(database, remote:) new(database, remote: remote).for end |
Instance Method Details
#for ⇒ Object
24 25 26 |
# File 'lib/pgchief/database/backups.rb', line 24 def for remote ? remote_backups : local_backups end |
#local_backups ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/pgchief/database/backups.rb', line 40 def local_backups Dir["#{Pgchief::Config.backup_dir}#{database}-*.dump"] .sort_by { |f| File.mtime(f) } .reverse .last(3) .map { |f| File.basename(f) } end |
#remote_backups ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pgchief/database/backups.rb', line 28 def remote_backups @remote_backups ||= client.list_objects( bucket: bucket, prefix: "#{path}#{database}-" ).contents .map(&:key) .sort .last(3) .reverse .map { |f| File.basename(f) } end |