File: postgres.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (31 lines) | stat: -rw-r--r-- 922 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true
module Backup
  module Dump
    class Postgres
      include Backup::Helper

      # Owner can read/write, group no permission, others no permission
      FILE_PERMISSION = 0o600

      # Triggers PgDump and outputs to the provided file path
      #
      # @param [String] output_file_path full path to the output destination
      # @param [Gitlab::Backup::Cli::Utils::PgDump] pg_dump
      # @return [Boolean] whether pg_dump finished with success
      def dump(output_file_path, pg_dump)
        compress_rd, compress_wr = IO.pipe

        compress_pid = spawn(compress_cmd, in: compress_rd, out: [output_file_path, 'w', FILE_PERMISSION])
        compress_rd.close

        dump_pid = pg_dump.spawn(output: compress_wr)
        compress_wr.close

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