Class: Backup::Dump::Postgres

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/backup/dump/postgres.rb

Constant Summary collapse

FILE_PERMISSION =
0o600

Instance Method Summary collapse

Methods included from Helper

#access_denied_error, #gzip_cmd, #resource_busy_error

Instance Method Details

#dump(database_name, output_file, pgsql_args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/backup/dump/postgres.rb', line 9

def dump(database_name, output_file, pgsql_args)
  compress_rd, compress_wr = IO.pipe
  compress_pid = spawn(gzip_cmd, in: compress_rd, out: [output_file, 'w', FILE_PERMISSION])
  compress_rd.close

  dump_pid = Process.spawn('pg_dump', *pgsql_args, database_name, out: compress_wr)
  compress_wr.close

  [compress_pid, dump_pid].all? do |pid|
    Process.waitpid(pid)
    $?.success?
  end
end