require 'logger' require 'pathname' require 'fileutils' require 'zlib' require 'net/ftp' require 'pg' require 'pg_export/version' require 'pg_export/logging' require 'pg_export/configuration' require 'pg_export/errors' require 'pg_export/dump' require 'pg_export/actions' require 'pg_export/ftp_service' require 'pg_export/ftp_service/connection' class PgExport include Logging def initialize @config = Configuration.new yield config if block_given? config.validate end def call initialize_dump concurrently do |job| job << Thread.new { perform_local_job } job << Thread.new { initialize_ftp_service } end perform_ftp_job self end private attr_reader :config attr_accessor :ftp_service, :dump def initialize_dump self.dump = Dump.new(config.database, config.dumpfile_dir) end def initialize_ftp_service self.ftp_service = FtpService.new(config.ftp_params) end def concurrently t = [] yield t t.each(&:join) end def perform_local_job CreateDump.new(dump).call CompressDump.new(dump).call RemoveOldDumps.new(dump, config.keep_dumps).call end def perform_ftp_job SendDumpToFtp.new(dump, ftp_service).call RemoveOldDumpsFromFtp.new(dump, ftp_service, config.keep_ftp_dumps).call end end