summaryrefslogtreecommitdiff
path: root/lib/backup/dump/postgres.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/backup/dump/postgres.rb')
-rw-r--r--lib/backup/dump/postgres.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/backup/dump/postgres.rb b/lib/backup/dump/postgres.rb
new file mode 100644
index 00000000000..1a5128b5a6b
--- /dev/null
+++ b/lib/backup/dump/postgres.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+module Backup
+ module Dump
+ class Postgres
+ include Backup::Helper
+
+ FILE_PERMISSION = 0o600
+
+ 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
+ end
+ end
+end