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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/rmybackup/base.rb', line 5
def load_config(file)
file = File.expand_path(file)
if not File.exists? file
puts "Can't load config file: #{file}"
exit 1
end
@config = YAML::load(File.open(file))
@config['file'] = file
@error = Array.new
if @config['gzip_command'].nil?
@config['gzip_command'] = `which gzip`.chop
end
if @config['mysqldump_command'].nil?
@config['mysqldump_command'] = `which mysqldump`.chop
end
if not @config['push'].nil?
@config['push'] = Array.new << @config['push'] if not @config['push'].kind_of? Array
if @config['rsync_command'].nil?
@config['rsync_command'] = `which rsync`.chop
end
@error << "Can't locate rsync command: #{@config['rsync_command']}" unless File.exists? @config['rsync_command']
else
@config['push'] = false
end
@error << "Can't locate gzip command: #{@config['gzip_command']}" unless File.exists? @config['gzip_command']
@error << "Can't locate mysqldump command: #{@config['mysqldump_command']}" unless File.exists? @config['mysqldump_command']
@config['remove_after'] = @config['remove_after'] || false
@config['only_keep'] = @config['only_keep'] || false
@config['use_mycnf_credentials'] = @config['use_mycnf_credentials'] ? true : false
@config['username'] = @config['username'] || false
@config['password'] = @config['password'] || false
@config['host'] = @config['host'] || false
@config['backup_dir'] = File.expand_path @config['backup_dir']
if not File.directory? @config['backup_dir']
@error << "No Such Backup Directory #{@config['backup_dir']}"
else
if not File.writable? @config['backup_dir']
@error << "Can't write to the backup directory - #{@config['backup_dir']}"
end
end
if @error.empty?
return true
else
@error.each {|e| puts "#{e}\n" }
exit 1
end
end
|