Commit 10222937 authored by Stan Hu's avatar Stan Hu

Ignore known restore from backup errors

The Omnibus user does not have access to create or drop extensions or
schema. We can ignore these errors since they shouldn't change restore
from backup.

In addition, flush the output so that the prompt shows up.
parent a6dbbaaf
...@@ -8,6 +8,14 @@ module Backup ...@@ -8,6 +8,14 @@ module Backup
attr_reader :progress attr_reader :progress
attr_reader :config, :db_file_name attr_reader :config, :db_file_name
IGNORED_ERRORS = [
# Ignore the DROP errors; recent database dumps will use --if-exists with pg_dump
/does not exist$/,
# User may not have permissions to drop extensions or schemas
/must be owner of/
].freeze
IGNORED_ERRORS_REGEXP = Regexp.union(IGNORED_ERRORS).freeze
def initialize(progress, filename: nil) def initialize(progress, filename: nil)
@progress = progress @progress = progress
@config = YAML.load_file(File.join(Rails.root, 'config', 'database.yml'))[Rails.env] @config = YAML.load_file(File.join(Rails.root, 'config', 'database.yml'))[Rails.env]
...@@ -49,6 +57,8 @@ module Backup ...@@ -49,6 +57,8 @@ module Backup
end end
report_success(success) report_success(success)
progress.flush
raise Backup::Error, 'Backup failed' unless success raise Backup::Error, 'Backup failed' unless success
end end
...@@ -83,6 +93,10 @@ module Backup ...@@ -83,6 +93,10 @@ module Backup
protected protected
def ignore_error?(line)
IGNORED_ERRORS_REGEXP.match?(line)
end
def execute_and_track_errors(cmd, decompress_rd) def execute_and_track_errors(cmd, decompress_rd)
errors = [] errors = []
...@@ -97,8 +111,7 @@ module Backup ...@@ -97,8 +111,7 @@ module Backup
Thread.new do Thread.new do
until (raw_line = stderr.gets).nil? until (raw_line = stderr.gets).nil?
warn(raw_line) warn(raw_line)
# Recent database dumps will use --if-exists with pg_dump errors << raw_line unless ignore_error?(raw_line)
errors << raw_line unless raw_line =~ /does not exist$/
end end
end end
......
...@@ -38,7 +38,7 @@ RSpec.describe Backup::Database do ...@@ -38,7 +38,7 @@ RSpec.describe Backup::Database do
context 'when the restore command prints errors' do context 'when the restore command prints errors' do
let(:visible_error) { "This is a test error\n" } let(:visible_error) { "This is a test error\n" }
let(:noise) { "Table projects does not exist\n" } let(:noise) { "Table projects does not exist\nmust be owner of extension pg_trgm\n" }
let(:cmd) { %W[#{Gem.ruby} -e $stderr.write("#{noise}#{visible_error}")] } let(:cmd) { %W[#{Gem.ruby} -e $stderr.write("#{noise}#{visible_error}")] }
it 'filters out noise from errors' do it 'filters out noise from errors' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment