Skip to content

Commit

Permalink
[PostgresAdmin] Fix backup_type being ignored
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NickLaMuro committed Nov 7, 2018
1 parent 552d3d6 commit caf0f38
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/gems/pending/util/postgres_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit caf0f38

Please sign in to comment.