Class: Backy::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/backy/configuration.rb

Constant Summary collapse

DEFAULTS =
{
  pg_host: nil,
  pg_port: nil,
  pg_database: nil,
  pg_username: nil,
  pg_password: nil,
  s3_region: nil,
  s3_access_key: nil,
  s3_secret: nil,
  s3_bucket: nil,
  s3_prefix: "./db/dump/",
  app_name: "backy",
  environment: "development",
  use_parallel: false,
  pause_replication: true,
  log_file: "./log/backy.log",
  local_backup_path: nil
}.freeze
CONFIG_FILE_NAME =
".backyrc"

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



32
33
34
35
36
# File 'lib/backy/configuration.rb', line 32

def initialize
  DEFAULTS.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Method Details

#loadObject



38
39
40
41
42
# File 'lib/backy/configuration.rb', line 38

def load
  load_config_file

  load_from_env
end

#log_fileObject



79
80
81
# File 'lib/backy/configuration.rb', line 79

def log_file
  @log_file ||= default_log_file
end

#multicoreObject

Determine if the system is multicore



75
76
77
# File 'lib/backy/configuration.rb', line 75

def multicore
  @multicore ||= Etc.nprocessors > 1
end

#pause_replication?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/backy/configuration.rb', line 62

def pause_replication?
  pause_replication
end

#pg_urlObject



54
55
56
# File 'lib/backy/configuration.rb', line 54

def pg_url
  @pg_url ||= ENV["PG_URL"]
end

#pg_url=(url) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/backy/configuration.rb', line 44

def pg_url=(url)
  @pg_url = url
  pg_config = parse_postgres_uri(url)
  @pg_host = pg_config[:host]
  @pg_port = pg_config[:port]
  @pg_username = pg_config[:username]
  @pg_password = pg_config[:password]
  @pg_database = pg_config[:database_name]
end

#pigz_installedObject

Detect if pigz binary is available If it is, use it to speed up the dump pigz is a parallel gzip implementation zlib.net/pigz/



70
71
72
# File 'lib/backy/configuration.rb', line 70

def pigz_installed
  @pigz_installed ||= system("which pigz > /dev/null 2>&1")
end

#use_parallel?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/backy/configuration.rb', line 58

def use_parallel?
  use_parallel && pigz_installed && multicore
end