Sha256: b09367b87eacaaba8f026d1307eefa9eb164e0b675a4bbfb153d3165761b1e0c

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'logger'
require 'tempfile'
require 'zlib'
require 'net/ftp'

require 'pg_export/version'
require 'pg_export/logging'
require 'pg_export/errors'
require 'pg_export/configuration'
require 'pg_export/concurrency'
require 'pg_export/entities/dump/size_human'
require 'pg_export/entities/dump/base'
require 'pg_export/entities/sql_dump'
require 'pg_export/entities/compressed_dump'
require 'pg_export/services/ftp_service'
require 'pg_export/services/ftp_service/connection'
require 'pg_export/services/utils'
require 'pg_export/services/dump_storage'

class PgExport
  include Concurrency

  def initialize
    @config = Configuration.new
    yield config if block_given?
    config.validate
  end

  def call
    concurrently do |job|
      job << create_dump
      job << initialize_dump_storage
    end
    dump_storage.upload(dump)
    dump_storage.remove_old(keep: config.keep_dumps)
    self
  end

  private

  attr_reader :config
  attr_accessor :dump, :dump_storage

  def initialize_dump_storage
    ftp_service = FtpService.new(config.ftp_params)
    self.dump_storage = DumpStorage.new(ftp_service, config.database)
  end

  def create_dump
    sql_dump = Utils.create_dump(config.database)
    compressed_dump = Utils.compress(sql_dump)
    self.dump = compressed_dump
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pg_export-0.3.0 lib/pg_export.rb