Module: System

Included in:
AwsAdapter, Backup2s3, BackupManager, MysqlAdapter, PostgresqlAdapter, S3cmdAdapter
Defined in:
lib/system.rb

Class Method Summary collapse

Class Method Details

.clean(str) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/system.rb', line 44

def self.clean(str)
  str.gsub!(".", "-dot-")
  str.gsub!("_", "-")
  str.gsub!("\n", "")
  str.gsub!(/[^0-9a-z\-_]/i, '')
  return str
end

.db_credentialsObject



10
11
12
13
# File 'lib/system.rb', line 10

def self.db_credentials
  db_config = YAML.load_file("#{Rails.root.to_s}/config/database.yml")
  db_config[Rails.env]
end

.hostnameObject



6
7
8
# File 'lib/system.rb', line 6

def self.hostname
  `hostname`.to_str.gsub!("\n", "")
end

.prompt(prompt, noecho = false) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/system.rb', line 52

def self.prompt(prompt, noecho = false)
  STDOUT.print prompt
  STDOUT.flush
  if noecho
    return STDIN.noecho(&:gets).chomp
  else
    return STDIN.gets.chomp
  end
end

.run(command) ⇒ Object

Run system commands



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

def self.run(command)
  result = system(command)
  raise("error, process exited with status #{$?.exitstatus}") unless result
end

.tarzip_folders(folders) ⇒ Object

Creates app tar file



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/system.rb', line 22

def self.tarzip_folders(folders)
  application_tar = Tempfile.new("app")
  ex_folders = ''
  folders.each { |folder|
    unless File.exist?(folder)
      print "\nWARNING: Folder \'" + folder + "\' does not exist! Excluding from backup."
    else
      ex_folders << folder << ' '
    end
  }
  if ex_folders.length > 0
    cmd = "tar --dereference -czpf #{application_tar.path} #{ex_folders}"
    run(cmd)
  end
  return application_tar
end

.unzip_file(tarball) ⇒ Object



39
40
41
42
# File 'lib/system.rb', line 39

def self.unzip_file(tarball)
  cmd = "tar xpf #{tarball.path}"
  run(cmd)
end