gat 0.2.8 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +15 -0
- data/PostInstall.txt +7 -9
- data/Rakefile +3 -1
- data/lib/gat.rb +1 -1
- data/lib/gat/action/shell_command.rb +18 -17
- data/lib/gat/boot.rb +1 -1
- data/lib/gat/checks.rb +2 -4
- data/lib/gat/condition.rb +80 -0
- data/lib/gat/dependence/folder.rb +4 -6
- data/lib/gat/dependence/program.rb +6 -2
- data/lib/gat/extends.rb +27 -12
- data/lib/gat/logger.rb +2 -2
- data/lib/gat/sample.yml +195 -0
- data/lib/gat/version.rb +7 -5
- data/lib/gatgets/dar_backup/dar_backup.rb +92 -133
- data/lib/gatgets/dar_backup/dar_backup.yml +20 -61
- data/lib/gatgets/dar_backup/launcher.rb +14 -12
- data/lib/gatgets/dar_backup/system_backup.rb +143 -0
- data/lib/gatgets/dar_backup/templates/list_backups.erb +12 -19
- data/lib/gatgets/synchronization/detect_block_devices.sh +27 -0
- data/lib/gatgets/synchronization/synchronization.rb +1 -1
- data/test/test_gat.rb +1 -26
- metadata +30 -6
@@ -3,28 +3,28 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'gatgets/dar_backup/dar_backup'
|
5
5
|
|
6
|
-
class
|
6
|
+
class LauncherForGatgetDarBackup < GatgetDarBackup #:nodoc:
|
7
7
|
end
|
8
8
|
|
9
9
|
# default options... see all options at Gatget config file GAT_ROOT + /lib/gatgets/dar_backup/dar_backup.yml
|
10
10
|
|
11
11
|
options = {
|
12
|
-
# include gat common config
|
13
|
-
'
|
14
|
-
|
15
|
-
'
|
16
|
-
|
17
|
-
'
|
18
|
-
|
19
|
-
'
|
20
|
-
|
12
|
+
'gat_config' => '/etc/gat/gat.yml', # include gat common config
|
13
|
+
'gatget_config' => { # gatget config
|
14
|
+
'folders' => { # backup folder
|
15
|
+
'backups_folder' => { 'path' => '/mnt/backups' }
|
16
|
+
},
|
17
|
+
'operations' => { # change user allowed to run backup operations, by default only root is allowed
|
18
|
+
'do_backup' => { 'users' => [ 'root' ] },
|
19
|
+
'list_backups' => { 'users' => [ 'root' ] },
|
20
|
+
'search' => { 'users' => [ 'root' ] }
|
21
21
|
},
|
22
22
|
# static values
|
23
23
|
'static' => {
|
24
24
|
# week days in which complete backup is performed
|
25
25
|
'complet_backup_days' => [ 0 ],
|
26
26
|
# number of complet backups are going to be stored at the machine
|
27
|
-
'number_backup_stored' =>
|
27
|
+
'number_backup_stored' => 1,
|
28
28
|
# disk space limit to perform backup, in megas
|
29
29
|
'space_thresold' => '3000M',
|
30
30
|
# folders to exclude from backup
|
@@ -32,6 +32,8 @@ options = {
|
|
32
32
|
'sys', 'usr', 'cdrom', 'lib', 'lost+found', 'mnt', 'proc', 'bin',
|
33
33
|
'srv', 'tmp', 'home',
|
34
34
|
'var', 'etc' ],
|
35
|
+
'dar_encrypt_passwd' => 'none',
|
36
|
+
'dar_decrypt_passwd' => 'none',
|
35
37
|
# should gatget does a mysqldumps
|
36
38
|
'mysql_dumps' => false,
|
37
39
|
'mysql_user' => '',
|
@@ -41,4 +43,4 @@ options = {
|
|
41
43
|
}
|
42
44
|
|
43
45
|
# Launch Gatget
|
44
|
-
|
46
|
+
LauncherForGatgetDarBackup.launch(options, ARGV)
|
@@ -0,0 +1,143 @@
|
|
1
|
+
class SystemBackup
|
2
|
+
|
3
|
+
attr_accessor :name
|
4
|
+
attr_accessor :isolate
|
5
|
+
attr_accessor :isolate_slices
|
6
|
+
attr_accessor :slices
|
7
|
+
attr_accessor :size
|
8
|
+
attr_accessor :size_nice
|
9
|
+
attr_accessor :dump
|
10
|
+
attr_accessor :type
|
11
|
+
attr_accessor :folder
|
12
|
+
attr_accessor :current
|
13
|
+
attr_accessor :full_dar_path
|
14
|
+
|
15
|
+
def initialize(backup_file, backup_folder_path, current_folder)
|
16
|
+
@name = backup_file.split('.').first
|
17
|
+
@isolate = has_isolate?("#{ backup_folder_path }/#{ @name }")
|
18
|
+
@dump = has_dump?("#{ backup_folder_path }/#{ @name }")
|
19
|
+
@slices = slices_for(backup_folder_path, @name)
|
20
|
+
@size = 0
|
21
|
+
@slices.each do |slice|
|
22
|
+
@size += File.size("#{ backup_folder_path }/#{ slice }")
|
23
|
+
end
|
24
|
+
@type = @name.include?('complet') ? 'complet' : 'diff'
|
25
|
+
@folder = backup_folder_path.split('/').last
|
26
|
+
@current = @folder == current_folder
|
27
|
+
|
28
|
+
@full_dar_path = "#{ backup_folder_path }/#{ @name }"
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def self.find(how_many, path_to_search, conditions = {})
|
34
|
+
|
35
|
+
current_folder = nil
|
36
|
+
if File.exists?("#{ path_to_search }/current")
|
37
|
+
current_folder = File.readlink("#{ path_to_search }/current").gsub(/\//,'')
|
38
|
+
end
|
39
|
+
|
40
|
+
all_backups = get_backups_in(path_to_search, current_folder)
|
41
|
+
backups = []
|
42
|
+
|
43
|
+
all_backups.each do |backup|
|
44
|
+
backups << backup if SystemBackup.valid_backup_file?(backup, conditions)
|
45
|
+
end
|
46
|
+
|
47
|
+
if how_many == :first
|
48
|
+
return_backups = backups.first
|
49
|
+
elsif how_many == :last
|
50
|
+
return_backups = backups.last
|
51
|
+
elsif how_many == :all
|
52
|
+
return_backups = backups
|
53
|
+
else
|
54
|
+
raise Gat::GatgetProcessException.new("Undefined return backups symbol #{ how_many }", "find")
|
55
|
+
end
|
56
|
+
|
57
|
+
return_backups
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def search_pattern(pattern)
|
62
|
+
unless self.has_dump?(self.full_dar_path)
|
63
|
+
raise Gat::GatgetProcessException.new("Unable to search_pattern withour dump. Create it first", "search_pattern")
|
64
|
+
end
|
65
|
+
|
66
|
+
results = ''
|
67
|
+
|
68
|
+
dump_file = File.open("#{ self.full_dar_path }_dump", "r")
|
69
|
+
|
70
|
+
dump_file.each_line do |line|
|
71
|
+
if line.include?(pattern)
|
72
|
+
results << line
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
results
|
77
|
+
end
|
78
|
+
|
79
|
+
protected
|
80
|
+
def has_isolate?(path)
|
81
|
+
File.exists?("#{ path }_isolate.1.dar")
|
82
|
+
end
|
83
|
+
|
84
|
+
def has_dump?(path)
|
85
|
+
File.exists?("#{ path }_dump")
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
def self.valid_backup_file?(backup, conditions)
|
90
|
+
|
91
|
+
valid_conditions = [ :current, :dump, :isolate, :folder, :type]
|
92
|
+
|
93
|
+
conditions.each_key do |cond|
|
94
|
+
unless valid_conditions.include?(cond)
|
95
|
+
raise Gat::GatgetProcessException.new("Find backup with condition #{ cond }. Condition not valid", "valid_backup_file?")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
passed = true
|
100
|
+
conditions.each_pair do |condition_name, condition_value|
|
101
|
+
unless backup.send(condition_name) == condition_value
|
102
|
+
passed = false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
passed
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.get_backups_in(path_to_search, current_folder)
|
110
|
+
|
111
|
+
backups = []
|
112
|
+
(Dir.entries(path_to_search) - ['current', '.', '..']).each do |backup_folder|
|
113
|
+
|
114
|
+
backup_folder_path = "#{ path_to_search }/#{ backup_folder }"
|
115
|
+
|
116
|
+
(Dir.entries(backup_folder_path) - ['..', '.' ]).each do |backup_file|
|
117
|
+
|
118
|
+
if SystemBackup.is_reference_backup_file?(backup_file)
|
119
|
+
backups << SystemBackup.new(backup_file, backup_folder_path, current_folder)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
backups
|
124
|
+
end
|
125
|
+
|
126
|
+
# reference file is the first slice of backup. No isolate, no dump
|
127
|
+
def self.is_reference_backup_file?(name)
|
128
|
+
name.include?('1.dar') and not name.include?('_isolate') and not name.include?('_dump')
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
def slices_for(path, name)
|
133
|
+
slices = []
|
134
|
+
(Dir.entries(path) - ['.', '..']).each do |entry|
|
135
|
+
if entry.include?(name) and not entry.include?('isolate') and not entry.include?('dump')
|
136
|
+
slices << entry
|
137
|
+
end
|
138
|
+
end
|
139
|
+
slices
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
end
|
@@ -1,31 +1,24 @@
|
|
1
1
|
% system_backups = operation.gatget.get_dependence_value("variable", "system_backups") || []
|
2
|
-
%
|
3
|
-
% system_backups = system_backups.select{ |backup| !backup['isolate']}
|
4
|
-
% if system_backups.empty? and catalog_backups.empty?
|
2
|
+
% if system_backups.empty?
|
5
3
|
|
6
4
|
ERROR: No Backups stored at System
|
7
5
|
|
8
6
|
% else
|
9
7
|
|
10
|
-
Listintg Backups in File System
|
8
|
+
Listintg Backups in File System:
|
11
9
|
|
12
10
|
- Backup Folder : <%= operation.gatget.get_dependence_value("folders", "backups_folder_data_local") %>
|
13
|
-
- Catalog : <%= operation.gatget.get_flag("catalog_exists") ? operation.gatget.get_dependence_value("variable", "catalog_path") : "Catalog doesnt exists!" %>
|
14
11
|
|
15
|
-
/<%= '-' *
|
16
|
-
| <%= '
|
17
|
-
|
18
|
-
%
|
19
|
-
%
|
20
|
-
|
21
|
-
% in_catalog = 'No'
|
22
|
-
% id_catalog = '-'
|
23
|
-
% else
|
24
|
-
% in_catalog = 'Yes'
|
25
|
-
% id_catalog = is_in_catalog.first['id'] || 'x'
|
26
|
-
% end
|
27
|
-
| <%= system_backup['name'].ljust(50) %> | <%= system_backup['folder'].ljust(15) %> | <%= File.nice_size(system_backup['path']).ljust(10) %> | <%= in_catalog.ljust(10) %> | <%= id_catalog.ljust(6) %> | <%= system_backup['dar_name'].ljust(40) %> |
|
12
|
+
/<%= '-' * 122 %>\
|
13
|
+
| <%= 'Backup Name'.ljust(40) %> | <%= 'File Folder'.ljust(15) %> | <%= 'Size'.ljust(10) %> | <%= 'Slices'.ljust(7) %> | <%= 'Isolate?'.ljust(10) %> | <%= 'Dumped?'.ljust(10) %> | <%= 'Current?'.ljust(10) %> |
|
14
|
+
% last_folder = ''
|
15
|
+
% system_backups.each do |backup|
|
16
|
+
% if last_folder != backup.folder
|
17
|
+
|<%= '-' * 122 %>|
|
28
18
|
% end
|
29
|
-
|
19
|
+
| <%= backup.name.ljust(40) %> | <%= backup.folder.ljust(15) %> | <%= nice_file_size(backup.size).ljust(10) %> | <%= backup.slices.count.to_s.ljust(7) %> | <%= (backup.isolate ? "Yes" : "No").ljust(10) %> | <%= (backup.dump ? "Yes" : "No").ljust(10) %> | <%= (backup.current ? "Yes" : "No").ljust(10) %> |
|
20
|
+
% last_folder = backup.folder
|
21
|
+
% end
|
22
|
+
\<%= '-' * 122 %>/
|
30
23
|
|
31
24
|
%end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# Maybe we want to show only devices with ID_FS_USAGE
|
4
|
+
|
5
|
+
for block in `ls -d /sys/block/*`; do
|
6
|
+
echo "Comprobando $block"
|
7
|
+
USB=`udevinfo -a -p $block | grep "SUBSYSTEMS==\"usb\""`
|
8
|
+
if [ "x$USB" != "x" ]; then
|
9
|
+
echo "======= $block =========="
|
10
|
+
udevinfo -q all -p $block
|
11
|
+
for option in `echo "ATTR{size} ATTRS{serial} ATTRS{model} ATTRS{vendor}"`; do
|
12
|
+
udevinfo -a -p $block | grep "$option"
|
13
|
+
done
|
14
|
+
echo
|
15
|
+
# Look for partitions
|
16
|
+
for part in `find $block/* -name partition`; do
|
17
|
+
part_name=`echo $part | sed -e "s0/partition00"`
|
18
|
+
echo "========== PARTITION $part_name =========="
|
19
|
+
udevinfo -q all -p $part_name
|
20
|
+
for option in `echo "KERNEL== SUBSYSTEM== DRIVER== ATTR{partition} ATTR{start} ATTR{stat} ATTR{size}"`; do
|
21
|
+
udevinfo -a -p $part_name | grep "$option"
|
22
|
+
done
|
23
|
+
|
24
|
+
done
|
25
|
+
fi
|
26
|
+
done
|
27
|
+
|
@@ -67,7 +67,7 @@ class GatgetSynchronization < Gat::Base
|
|
67
67
|
def onfail
|
68
68
|
|
69
69
|
unless self.config['email_config']
|
70
|
-
raise Gat::GatgetConfigException.new("Default email config is empty at gatget.config['email_config']", "
|
70
|
+
raise Gat::GatgetConfigException.new("Default email config is empty at gatget.config['email_config']", "synchronization:onfail")
|
71
71
|
end
|
72
72
|
|
73
73
|
unless self.config['email_config']['send_to']
|
data/test/test_gat.rb
CHANGED
@@ -1,36 +1,11 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
|
-
|
4
|
-
# define Test Class
|
5
|
-
GATGET_TESTER_ROOT = File.expand_path(File.dirname(__FILE__))
|
6
|
-
class GatgetTester < Gat::Base
|
7
|
-
|
8
|
-
def test_ruby_method
|
9
|
-
'tested'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
class TesterLauncher < GatgetTester
|
15
|
-
end
|
16
|
-
|
17
3
|
class TestGat < Test::Unit::TestCase
|
18
4
|
|
19
5
|
def setup
|
20
6
|
end
|
21
7
|
|
22
|
-
def
|
23
|
-
|
24
|
-
# Testing is done with a testing yml File
|
25
|
-
# so, process it!!!
|
26
|
-
test_options = { 'config_file_name' => "#{ GATGET_TESTER_ROOT }/test.yml" }
|
27
|
-
TesterLauncher.launch(test_options, ['test'])
|
28
|
-
|
29
|
-
|
30
|
-
|
8
|
+
def test_truth
|
31
9
|
assert true
|
32
10
|
end
|
33
|
-
|
34
|
-
def test_de
|
35
|
-
end
|
36
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gnoxys
|
@@ -9,9 +9,29 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-22 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: tmail
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.3
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: open4
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "1.0"
|
34
|
+
version:
|
15
35
|
- !ruby/object:Gem::Dependency
|
16
36
|
name: rubyforge
|
17
37
|
type: :development
|
@@ -66,10 +86,11 @@ files:
|
|
66
86
|
- bin/gat
|
67
87
|
- lib/gat.rb
|
68
88
|
- lib/gat/action/base.rb
|
69
|
-
- lib/gat/action/shell_command.rb
|
70
89
|
- lib/gat/action/ruby_method.rb
|
90
|
+
- lib/gat/action/shell_command.rb
|
71
91
|
- lib/gat/boot.rb
|
72
92
|
- lib/gat/checks.rb
|
93
|
+
- lib/gat/condition.rb
|
73
94
|
- lib/gat/debug.rb
|
74
95
|
- lib/gat/dependence/argument.rb
|
75
96
|
- lib/gat/dependence/base.rb
|
@@ -83,8 +104,10 @@ files:
|
|
83
104
|
- lib/gat/launcher.rb
|
84
105
|
- lib/gat/logger.rb
|
85
106
|
- lib/gat/operation.rb
|
107
|
+
- lib/gat/sample.yml
|
86
108
|
- lib/gat/version.rb
|
87
109
|
- lib/gatgets/dar_backup/dar_backup.rb
|
110
|
+
- lib/gatgets/dar_backup/system_backup.rb
|
88
111
|
- lib/gatgets/dar_backup/dar_backup.yml
|
89
112
|
- lib/gatgets/dar_backup/launcher.rb
|
90
113
|
- lib/gatgets/dar_backup/templates/list_backups.erb
|
@@ -92,11 +115,12 @@ files:
|
|
92
115
|
- lib/gatgets/gatgets_manager/gatgets_manager.rb
|
93
116
|
- lib/gatgets/gatgets_manager/gatgets_manager.yml
|
94
117
|
- lib/gatgets/gatgets_manager/templates/list.erb
|
118
|
+
- lib/gatgets/synchronization/README
|
119
|
+
- lib/gatgets/synchronization/launcher.rb
|
120
|
+
- lib/gatgets/synchronization/launcher_cron.sh
|
95
121
|
- lib/gatgets/synchronization/synchronization.rb
|
96
122
|
- lib/gatgets/synchronization/synchronization.yml
|
97
|
-
- lib/gatgets/synchronization/
|
98
|
-
- lib/gatgets/synchronization/launcher.rb
|
99
|
-
- lib/gatgets/synchronization/README
|
123
|
+
- lib/gatgets/synchronization/detect_block_devices.sh
|
100
124
|
has_rdoc: true
|
101
125
|
homepage:
|
102
126
|
licenses: []
|