Sha256: 65543b6f58bfc16e9eed9d376d3a45943b0bc0db701138d2cd5332215c5e92d6

Contents?: true

Size: 753 Bytes

Versions: 1

Compression:

Stored size: 753 Bytes

Contents

class PgExport
  class BashUtils
    include Logging

    def initialize(database_name)
      @database_name = database_name
    end

    def create_dump
      dump = PlainDump.new
      Open3.popen3("pg_dump -Fc --file #{dump.path} #{database_name}") do |_, _, err|
        error = err.read
        raise PgDumpError, error unless error.empty?
      end
      logger.info "Create #{dump}"
      dump
    end

    def restore_dump(dump, restore_database_name)
      Open3.popen3("pg_restore -c -d #{restore_database_name} #{dump.path}") do |_, _, err|
        error = err.read
        raise PgRestoreError, error if /FATAL/ =~ error
      end
      logger.info "Restore #{dump}"
      self
    end

    private

    attr_reader :database_name
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pg_export-0.5.0 lib/pg_export/services/bash_utils.rb