From caf0f38396029702f3fc5346698fe267204a7226 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 7 Nov 2018 15:00:19 -0600 Subject: [PATCH] [PostgresAdmin] Fix backup_type being ignored With the previous implementation, the code would always attempt to find the magic number of the file for a `pg_dump` before checking if the `backup_type` value was instead a `:basebackup`. When streaming a file, this would cause it to fail farther down the line since it would have strip some of the content off from the beginning of the file, invalidating it as a proper backup. This change fixes by forcing the check for the backup type first, and then by inspecting the file contents. --- lib/gems/pending/util/postgres_admin.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/gems/pending/util/postgres_admin.rb b/lib/gems/pending/util/postgres_admin.rb index 75ad5e4fc..0f53e3755 100644 --- a/lib/gems/pending/util/postgres_admin.rb +++ b/lib/gems/pending/util/postgres_admin.rb @@ -99,10 +99,12 @@ def self.backup(opts) def self.restore(opts) file = opts[:local_file] backup_type = opts.delete(:backup_type) - if backup_type == :pgdump || pg_dump_file?(file) - restore_pg_dump(opts) - elsif backup_type == :basebackup || base_backup_file?(file) - restore_pg_basebackup(file) + + case + when backup_type == :pgdump then restore_pg_dump(opts) + when backup_type == :basebackup then restore_pg_basebackup(file) + when pg_dump_file?(file) then restore_pg_dump(opts) + when base_backup_file?(file) then restore_pg_basebackup(file) else raise "#{file} is not a database backup" end