Module: PgDrive::Dump
- Defined in:
- lib/pg_drive/dump.rb
Class Method Summary collapse
Class Method Details
.call ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pg_drive/dump.rb', line 4 def call stdin, stdout, stderr, wait_thr = Open3.popen3( pg_env, BACKUP_CMD, pgroup: true ) tmpfile = Tempfile.new("pg_backup") tmpfile.write(stdout) tmpfile.rewind errors = stderr.read unless wait_thr.value.success? && errors.empty? raise BackupFailed, "Exit status: #{wait_thr.value.exitstatus}: #{errors}" end yield tmpfile ensure [stdin, stdout, stderr, tmpfile].compact.each(&:close) end |
.db_conf ⇒ Object
29 30 31 |
# File 'lib/pg_drive/dump.rb', line 29 def db_conf @db_conf ||= Rails.configuration.database_configuration[Rails.env] end |
.pg_env ⇒ Object
25 26 27 |
# File 'lib/pg_drive/dump.rb', line 25 def pg_env PG_ENV_MAP.map { |k, v| [k, db_conf[v].to_s] }.to_h end |