Class: Deploio::PostgresDatabaseBackupService
- Inherits:
-
Object
- Object
- Deploio::PostgresDatabaseBackupService
- Defined in:
- lib/deploio/postgres_database_backup_service.rb
Overview
Backups for the economy tier (kind: PostgresDatabase), where the database lives on a shared server we have no access to. The naming is confusing, but this is how Nine names them and how the resources appear, so prefer to stay consistent with that
Constant Summary collapse
- DEFAULT_EXTENSION =
".sql.zst"- BACKUP_SCHEDULE_LABEL =
"DatabaseBackupSchedule"
Instance Method Summary collapse
- #backups ⇒ Object
-
#capture ⇒ Object
Nine takes these backups on a schedule (you can even see them using
kubectl get databasebackupschedules.storage.nine.ch -n renuo-chess-tracker -o json) => there is no way to trigger one. - #default_destination ⇒ Object
- #download(destination:, db_name: nil) ⇒ Object
-
#initialize(db_ref:, data:, nctl_client:, name: nil, rclone_client_factory: nil) ⇒ PostgresDatabaseBackupService
constructor
A new instance of PostgresDatabaseBackupService.
Constructor Details
#initialize(db_ref:, data:, nctl_client:, name: nil, rclone_client_factory: nil) ⇒ PostgresDatabaseBackupService
Returns a new instance of PostgresDatabaseBackupService.
13 14 15 16 17 18 19 |
# File 'lib/deploio/postgres_database_backup_service.rb', line 13 def initialize(db_ref:, data:, nctl_client:, name: nil, rclone_client_factory: nil) @db_ref = db_ref @data = data || {} @nctl = nctl_client @name = name || db_ref.full_name @rclone_client_factory = rclone_client_factory || method(:build_rclone_client) end |
Instance Method Details
#backups ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/deploio/postgres_database_backup_service.rb', line 35 def backups @backups ||= begin entries = rclone.list(bucket_name) entries = entries.select { |e| own_backup?(e["Name"].to_s) } entries.sort_by { |e| e["ModTime"].to_s }.reverse end end |
#capture ⇒ Object
Nine takes these backups on a schedule
(you can even see them using kubectl get databasebackupschedules.storage.nine.ch -n renuo-chess-tracker -o json)
=> there is no way to trigger one.
28 29 30 31 32 33 |
# File 'lib/deploio/postgres_database_backup_service.rb', line 28 def capture raise Deploio::UnsupportedBackupOperationError, "'#{@db_ref.full_name}' is an economy-tier database. Those are backed up automatically " \ "on their configured schedule and cannot be captured manually.\n" \ "Use 'deploio pg backups list #{@name}' to see the available backups." end |
#default_destination ⇒ Object
21 22 23 |
# File 'lib/deploio/postgres_database_backup_service.rb', line 21 def default_destination "./#{@name}-latest-backup#{DEFAULT_EXTENSION}" end |
#download(destination:, db_name: nil) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/deploio/postgres_database_backup_service.rb', line 43 def download(destination:, db_name: nil) backup = backups.first unless backup raise Deploio::Error, "No backups found for '#{@db_ref.full_name}' in bucket '#{bucket_name}'." end rclone.download(bucket_name, backup["Name"], destination) backup end |