Sha256: 52f89056546e32be3aa5e1608fd1faa9e64c32bdf6e6c8c3df6d27ddcf471d39
Contents?: true
Size: 1.73 KB
Versions: 3
Compression:
Stored size: 1.73 KB
Contents
#!/usr/bin/env ruby require 'optparse' require 'ostruct' require 'pg_export' LOGS_TIMESTAMPED = ->(severity, datetime, progname, message) { "#{datetime} #{Process.pid} TID-#{Thread.current.object_id.to_s(36)}#{progname} #{severity}: #{message}\n" } LOGS_NORMAL = ->(_, _, _, message) { "#{message}\n" } options = OpenStruct.new option_parser = OptionParser.new do |opts| opts.banner = 'Usage: pg_export [options]' opts.on('-d', '--database DATABASE', '[Required] Name of the database to export') do |database| options.database = database end opts.on('-k', '--keep [KEEP]', Integer, '[Optional] Number of dump files to keep on FTP (default: 10)') do |keep| options.keep = keep end opts.on('-t', '--timestamped', '[Optional] Enables log messages with timestamps') do options.timestamped = true end opts.on('-h', '--help', 'Show this message') do puts opts exit end opts.separator "\nSetting can be verified by running following commands:" opts.on('-c', '--configuration', 'Prints the configuration') do puts PgExport::Configuration.new.to_s exit end opts.on('-f', '--ftp', 'Tries connecting to FTP to verify the connection') do PgExport::Logging.logger.formatter = LOGS_NORMAL PgExport::FtpService.new(PgExport::Configuration.new.ftp_params) exit end end begin option_parser.parse! PgExport::Logging.logger.formatter = options.timestamped ? LOGS_TIMESTAMPED : LOGS_NORMAL PgExport.new do |config| config.database = options.database if options.database config.keep_dumps = options.keep if options.keep end.call rescue OptionParser::MissingArgument, PgExport::InvalidConfigurationError => e puts "Error: #{e}" puts option_parser rescue PgExport::PgDumpError => e puts e end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
pg_export-0.3.2 | bin/pg_export |
pg_export-0.3.1 | bin/pg_export |
pg_export-0.3.0 | bin/pg_export |