Module: Backups::System

Included in:
Base, Crontab, Runner
Defined in:
lib/backups/system.rb

Instance Method Summary collapse

Instance Method Details

#delete(file) ⇒ Object



17
18
19
# File 'lib/backups/system.rb', line 17

def delete file
  exec "rm #{file}"
end

#delete_dir(start, stop = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/backups/system.rb', line 21

def delete_dir start, stop = nil
  return exec "rmdir #{start}" unless stop
  stop = stop.chomp("/")
  loop do
    exec "rmdir #{start}" if File.directory? start
    break if start == stop
    start = File.dirname(start)
  end
end

#exec(command) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/backups/system.rb', line 4

def exec command
  # $LOGGER.debug "Running #{command}" if $LOG_ACTIVE == 1
  return if $DRY_RUN

  output = `#{command}`
  if $?.exitstatus != 0
    raise RuntimeError, \
      "Command '#{command}' failed with exit code #{$?.exitstatus}."
  end

  return output.chomp()
end

#get_latest_s3(path) ⇒ Object



48
49
50
51
# File 'lib/backups/system.rb', line 48

def get_latest_s3 path
  # $LOGGER.debug  "aws s3 ls #{path}/|awk '{ print $4 }'|tail -n 1"
  exec "aws s3 ls #{path}/|awk '{ print $4 }'|tail -n 1"
end

#mkdir(dirname) ⇒ Object



35
36
37
# File 'lib/backups/system.rb', line 35

def mkdir dirname
  exec "mkdir -p #{dirname}"
end

#nuke_dir(dir) ⇒ Object



31
32
33
# File 'lib/backups/system.rb', line 31

def nuke_dir dir
  exec "rm -fr #{dir}"
end

#write(filename, contents) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/backups/system.rb', line 39

def write filename, contents
  commands = []
  commands << "cat << CONTENTS > #{filename}"
  commands << contents
  commands << "CONTENTS"

  exec commands.join("\n")
end