Sha256: efab467209c0ce1032e8f2f7966be3d067f1aee7eb639d2298790d54f0800d05

Contents?: true

Size: 762 Bytes

Versions: 2

Compression:

Stored size: 762 Bytes

Contents

class PgExport
  class Utils
    extend Logging

    def self.create_dump(database_name)
      dump = SqlDump.new
      out = `pg_dump -Fc --file #{dump.path} #{database_name} 2>&1`
      raise PgDumpError, out if /FATAL/ =~ out
      logger.info "Create #{dump}"
      dump
    end

    def self.compress(dump)
      dump_gz = CompressedDump.new
      dump_gz.open(:write) do |gz|
        gz.write(dump.read_chunk) until dump.eof?
      end

      logger.info "Create #{dump_gz}"
      dump_gz
    end

    def self.decompress(dump_gz)
      dump = SqlDump.new
      dump_gz.open(:read) do |gz|
        dump.write(gz.readpartial(Dump::Base::CHUNK_SIZE)) until gz.eof?
      end
      dump.rewind

      logger.info "Create #{dump}"
      dump
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pg_export-0.3.1 lib/pg_export/services/utils.rb
pg_export-0.3.0 lib/pg_export/services/utils.rb