Class: Backups::Crontab

Inherits:
Object
  • Object
show all
Includes:
Loader, System
Defined in:
lib/backups/crontab.rb

Constant Summary collapse

PADDING =
10

Constants included from Loader

Loader::CONFIG_ENV, Loader::CONFIG_SYSTEM, Loader::CONFIG_USER

Instance Method Summary collapse

Methods included from Loader

#load_configs

Methods included from System

#delete, #delete_dir, #exec, #get_latest_s3, #mkdir, #nuke_dir, #write

Constructor Details

#initializeCrontab

Returns a new instance of Crontab.



11
12
13
14
# File 'lib/backups/crontab.rb', line 11

def initialize
  load_configs
  @base = File.expand_path('../../..', __FILE__)
end

Instance Method Details

#installObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/backups/crontab.rb', line 43

def install
  last_log_active  = $LOG_ACTIVE
  $LOG_ACTIVE = 0

  install_mysql_groups

  content = get_install_lines()
  cronfile = "/tmp/crontab.new"
  write cronfile, content
  exec "crontab #{cronfile}"
  exec "rm #{cronfile}"
  exec "crontab -l"

  $LOG_ACTIVE = last_log_active
end

#listObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/backups/crontab.rb', line 16

def list
  paddings = {
    'job'    => 20,
    'backup' => 10,
    'verify' => 10,
  }

  rows = []
  rows << ["JOB", "CRONTAB", "INSTALL", "ENABLED"]

  $GLOBAL["jobs"].each do |job, config|
    backup   = config.fetch('backup',  {})
    crontab  = backup.fetch('crontab', {})
    crontime = get_crontime(crontab)
    install  = crontab.fetch('install', true)
    enabled  = config.fetch('enabled', true)

    rows << [job, crontime, install, enabled]
  end

  Tablelize::table rows
end

#showObject



39
40
41
# File 'lib/backups/crontab.rb', line 39

def show
  get_install_lines()
end