Module: RMyBackup

Defined in:
lib/rmybackup.rb,
lib/rmybackup/base.rb,
lib/rmybackup/push.rb,
lib/rmybackup/backup.rb,
lib/rmybackup/purge_files.rb,
lib/rmybackup/install_config.rb

Overview

Set the version

Defined Under Namespace

Classes: Backup, Base, Push

Constant Summary collapse

GEM_VERSION =
"0.3.7"

Class Method Summary collapse

Class Method Details

.edit_config_file(file) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rmybackup/install_config.rb', line 70

def self.edit_config_file(file)

  #See if the config file exists
  if not File.exists? file
    puts "The config file cannot be found: #{file}"
    exit 1
  end

  if editor
    exec "#{editor} #{file}"
  else
    puts "Can't locate vim and $EDITOR isn't set"
    exit 1
  end
end

.editorObject

Edit config Options



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rmybackup/install_config.rb', line 36

def self.editor
  if ENV['EDITOR'].nil?
    vim = `which vim`.chop
    if vim.empty?
      return false
    else
      return vim
    end
  else
    return ENV['EDITOR']
  end
end

.install_config(file = false) ⇒ Object

Install a baseline config file from the template



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rmybackup/install_config.rb', line 3

def self.install_config(file=false)
  #Default the file location
  if not file
    if File.writable_real?("/etc/")
      file = "/etc/rmybackup.conf"
    else
      file = "~/.rmybackup.conf"
    end
  end
  
  #Expand the path
  file = File.expand_path(file)
  
  if File.exists? file
    puts "#{file} already exists, do you want to overwrite it? (Y/n):"
    STDOUT.flush
    answer = gets.chomp
    exit 1 unless answer.upcase == "Y" or answer.upcase == "YES"
  end

  #Read Sample Config File
  config_file = File.read(File.expand_path("../../rmybackup/config_file.txt",__FILE__))

  begin
    File.open(file,'w') {|f| f.write(config_file) }
    puts "Installing #{file}"
  rescue Errno::EACCES
    puts "Can't write to - #{file}"
  end
  exit 0
end

.list_config_file(file) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rmybackup/install_config.rb', line 49

def self.list_config_file(file)
  if editor

    #See if the config file exists
    if not File.exists? file
      puts "The config file cannot be found: #{file}"
      exit 1
    end
    
    puts "Showing config file - #{file}:\n"
    File.open(file, "r") do |infile|
      while(line = infile.gets)
        puts line
      end
    end
  else
    puts "Can't locate vim and $EDITOR isn't set"
    exit 1
  end
end

.purge_days(path, days = false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rmybackup/purge_files.rb', line 5

def self.purge_days(path,days=false)
  return true unless days
  Dir["#{path}/*.sql.gz"].each do |file|
    mtime = File.mtime(File.expand_path(file))
    mdate = Date.parse("#{mtime.year}-#{mtime.month}-#{mtime.day}")
    date = Date.today - days
    if mdate < date
      puts "Cleaning up - #{file}"
      File.delete(file)
    end
  end
end

.purge_number(path, number = false) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rmybackup/purge_files.rb', line 18

def self.purge_number(path,number=false)
  return true unless number
  all_files = Dir[File.join(path,"*.gz")].sort_by {|f| File.mtime(f)}.reverse
  keep = all_files[0..number - 1]
  remove = all_files - keep
  remove.each do |f|
    File.delete f
  end
end