gat 0.2.8
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 +84 -0
- data/PostInstall.txt +22 -0
- data/README.txt +49 -0
- data/Rakefile +12 -0
- data/bin/gat +15 -0
- data/lib/gat.rb +323 -0
- data/lib/gat/action/base.rb +197 -0
- data/lib/gat/action/ruby_method.rb +35 -0
- data/lib/gat/action/shell_command.rb +185 -0
- data/lib/gat/boot.rb +63 -0
- data/lib/gat/checks.rb +136 -0
- data/lib/gat/debug.rb +29 -0
- data/lib/gat/dependence/argument.rb +62 -0
- data/lib/gat/dependence/base.rb +54 -0
- data/lib/gat/dependence/folder.rb +104 -0
- data/lib/gat/dependence/program.rb +36 -0
- data/lib/gat/email.rb +80 -0
- data/lib/gat/exceptions.rb +163 -0
- data/lib/gat/extends.rb +102 -0
- data/lib/gat/help.rb +79 -0
- data/lib/gat/interpreter.rb +93 -0
- data/lib/gat/launcher.rb +100 -0
- data/lib/gat/logger.rb +331 -0
- data/lib/gat/operation.rb +253 -0
- data/lib/gat/version.rb +20 -0
- data/lib/gatgets/dar_backup/dar_backup.rb +367 -0
- data/lib/gatgets/dar_backup/dar_backup.yml +387 -0
- data/lib/gatgets/dar_backup/launcher.rb +44 -0
- data/lib/gatgets/dar_backup/templates/list_backups.erb +31 -0
- data/lib/gatgets/dar_backup/templates/search.erb +33 -0
- data/lib/gatgets/gatgets_manager/gatgets_manager.rb +65 -0
- data/lib/gatgets/gatgets_manager/gatgets_manager.yml +71 -0
- data/lib/gatgets/gatgets_manager/templates/list.erb +9 -0
- data/lib/gatgets/synchronization/README +26 -0
- data/lib/gatgets/synchronization/launcher.rb +20 -0
- data/lib/gatgets/synchronization/launcher_cron.sh +69 -0
- data/lib/gatgets/synchronization/synchronization.rb +123 -0
- data/lib/gatgets/synchronization/synchronization.yml +144 -0
- data/test/test_gat.rb +36 -0
- data/test/test_helper.rb +3 -0
- metadata +131 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'gatgets/dar_backup/dar_backup'
|
5
|
+
|
6
|
+
class YourLauncherBackupScript < GatgetDarBackup #:nodoc:
|
7
|
+
end
|
8
|
+
|
9
|
+
# default options... see all options at Gatget config file GAT_ROOT + /lib/gatgets/dar_backup/dar_backup.yml
|
10
|
+
|
11
|
+
options = {
|
12
|
+
# include gat common config
|
13
|
+
'gat_config' => '/etc/gat/gat.yml',
|
14
|
+
# gatget config
|
15
|
+
'gatget_config' => {
|
16
|
+
# backup folder
|
17
|
+
'folders' => {
|
18
|
+
'backups_folder' => {
|
19
|
+
'path' => '/tmp/backup'
|
20
|
+
}
|
21
|
+
},
|
22
|
+
# static values
|
23
|
+
'static' => {
|
24
|
+
# week days in which complete backup is performed
|
25
|
+
'complet_backup_days' => [ 0 ],
|
26
|
+
# number of complet backups are going to be stored at the machine
|
27
|
+
'number_backup_stored' => 0,
|
28
|
+
# disk space limit to perform backup, in megas
|
29
|
+
'space_thresold' => '3000M',
|
30
|
+
# folders to exclude from backup
|
31
|
+
'exclude_folders' => [ 'boot', 'dev', 'lib64', 'media', 'opt', 'root', 'selinux',
|
32
|
+
'sys', 'usr', 'cdrom', 'lib', 'lost+found', 'mnt', 'proc', 'bin',
|
33
|
+
'srv', 'tmp', 'home',
|
34
|
+
'var', 'etc' ],
|
35
|
+
# should gatget does a mysqldumps
|
36
|
+
'mysql_dumps' => false,
|
37
|
+
'mysql_user' => '',
|
38
|
+
'mysql_password' => ''
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
# Launch Gatget
|
44
|
+
YourLauncherBackupScript.launch(options, ARGV)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
% system_backups = operation.gatget.get_dependence_value("variable", "system_backups") || []
|
2
|
+
% catalog_backups = operation.gatget.get_dependence_value("variable", "catalog_backups") || []
|
3
|
+
% system_backups = system_backups.select{ |backup| !backup['isolate']}
|
4
|
+
% if system_backups.empty? and catalog_backups.empty?
|
5
|
+
|
6
|
+
ERROR: No Backups stored at System
|
7
|
+
|
8
|
+
% else
|
9
|
+
|
10
|
+
Listintg Backups in File System and at Catalog:
|
11
|
+
|
12
|
+
- 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
|
+
|
15
|
+
/<%= '-' * 148 %>\
|
16
|
+
| <%= 'File Name'.ljust(50) %> | <%= 'File Folder'.ljust(15) %> | <%= 'Size'.ljust(10) %> | <%= 'In Catalog'.ljust(10) %> | <%= 'Dar ID'.ljust(6) %> | <%= 'Dar Name'.ljust(40) %> |
|
17
|
+
|<%= '-' * 148 %>|
|
18
|
+
% system_backups.each do |system_backup|
|
19
|
+
% is_in_catalog = catalog_backups.select{ |backup| backup['dar_name'] == system_backup['dar_name'] }
|
20
|
+
% if is_in_catalog.empty?
|
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) %> |
|
28
|
+
% end
|
29
|
+
\<%= '-' * 148 %>/
|
30
|
+
|
31
|
+
%end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
%# get the action object of search
|
2
|
+
% action_object = operation.get_action('search_simple')
|
3
|
+
% unless action_object.exit_level == 0
|
4
|
+
|
5
|
+
FAILED!!
|
6
|
+
Pattern didnt match any file or folder at Backups. Try to simplify the search.
|
7
|
+
For example, search 'bin' instead of 'bin/ls'
|
8
|
+
|
9
|
+
% else
|
10
|
+
% # we found results!
|
11
|
+
|
12
|
+
Search Results
|
13
|
+
--------------
|
14
|
+
|
15
|
+
File or Folder pattern was found at the following backups files
|
16
|
+
|
17
|
+
/<%= '-' * 94 %>\
|
18
|
+
| <%= 'Dar Name'.ljust(40) %> | <%= 'Dar ID'.ljust(6) %> | <%= 'Last modification Date'.ljust(40) %> |
|
19
|
+
|<%= '-' * 94 %>|
|
20
|
+
% action_object.output.each_line do |match_line|
|
21
|
+
% # line that include numbers are the result lines
|
22
|
+
% if match_line[/[0-9]/]
|
23
|
+
% backup_data = match_line.strip.split(' ')
|
24
|
+
% backup_id = backup_data.shift
|
25
|
+
% backup_catalog_file = operation.gatget.get_dependence_value("variable","catalog_backups").select { |b| b['id'] == backup_id }.first
|
26
|
+
| <%= backup_catalog_file['dar_name'].ljust(40) %> | <%= backup_id.ljust(6) %> | <%= backup_data.join(' ').ljust(40) %> |
|
27
|
+
% end
|
28
|
+
% end
|
29
|
+
\<%= '-' * 94 %>/
|
30
|
+
|
31
|
+
You can recover the file or folder with $> <%= $0 %> restore. See help for futher information.
|
32
|
+
|
33
|
+
% end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of GAT: http://gat.rubyforge.org
|
3
|
+
|
4
|
+
(c) 2008-2009 A.C. Gnoxys info@gnoxys.net
|
5
|
+
|
6
|
+
GAT (Gnoxys Administration Tools) is released under the GPL License 3 or higher.
|
7
|
+
You can get a copy of the license easily at http://www.gnu.org/licenses/gpl.html.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
10
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
11
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
12
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
13
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
14
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
15
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
=end
|
17
|
+
|
18
|
+
require 'gat'
|
19
|
+
|
20
|
+
GATGET_GATGETS_MANAGER_ROOT = File.expand_path(File.dirname(__FILE__))
|
21
|
+
|
22
|
+
class GatgetGatgetsManager < Gat::Base
|
23
|
+
|
24
|
+
# helpers
|
25
|
+
|
26
|
+
# valid_gatget_name will search at gagets path if we have a valid gatget script
|
27
|
+
def valid_gatget_name
|
28
|
+
|
29
|
+
gatget_name = get_dependence_value("arguments", "gatget_name")
|
30
|
+
gatgets_path = "#{ Gem.default_dir }/gems/gat-#{ Gat::VERSION }/lib/gatgets"
|
31
|
+
launcher_place = get_dependence_value("arguments", "launcher_path")
|
32
|
+
|
33
|
+
set_flag("launcher_exists", false)
|
34
|
+
|
35
|
+
if not Dir.new(gatgets_path).entries.include?(gatget_name)
|
36
|
+
self.logger.log('direct', 'valid_gatget_name', "\n ERROR: `#{ gatget_name }` not found at `#{ gatgets_path }` \n\n")
|
37
|
+
elsif not Dir.new("#{ gatgets_path }/#{ gatget_name }").entries.include?("launcher.rb")
|
38
|
+
self.logger.log('direct', 'valid_gatget_name', "\n ERROR: `launcher.rb` not found at `#{ gatgets_path }/#{ gatget_name }` \n\n")
|
39
|
+
else
|
40
|
+
set_flag("launcher_exists", true)
|
41
|
+
set_dependence_variable("gatgets_path", gatgets_path)
|
42
|
+
self.logger.log('direct', 'valid_gatget_name', "\n Launcher for gatget `#{ gatget_name }` will be placed at #{ launcher_place }/gatget_#{ gatget_name }` \n\n Edit and customize it.")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def list_system_gatgets
|
47
|
+
|
48
|
+
gatgets_path = "#{ Gem.default_dir }/gems/gat-#{ Gat::VERSION }/lib/gatgets"
|
49
|
+
|
50
|
+
|
51
|
+
avalaible_gatgets = {}
|
52
|
+
# get avalaible_gatgets but exclude gatget_manager one
|
53
|
+
(Dir.new(gatgets_path).entries - [ '.', '..' , 'gatgets_manager']).each do |gatget_folder|
|
54
|
+
if Dir.new("#{ gatgets_path }/#{ gatget_folder }").entries.include?("#{ gatget_folder }.yml")
|
55
|
+
gatget_config = YAML.load_file("#{ gatgets_path }/#{ gatget_folder }/#{ gatget_folder }.yml")
|
56
|
+
|
57
|
+
avalaible_gatgets[gatget_folder] = (gatget_config['description'] || "#{ gatget_folder.camelize } gatget")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
set_dependence_variable("avalaible_gatgets", avalaible_gatgets)
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Gatget Config Script for DarBackup Gatget
|
2
|
+
# -----------------------------------------
|
3
|
+
|
4
|
+
description: 'Gatgets manager'
|
5
|
+
|
6
|
+
static:
|
7
|
+
gatget_folders: []
|
8
|
+
|
9
|
+
arguments:
|
10
|
+
gatget_name:
|
11
|
+
description: Camelized gatget name, for example, dar_backup
|
12
|
+
launcher_path:
|
13
|
+
description: Path where launcher will be placed
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
folders:
|
18
|
+
|
19
|
+
programs:
|
20
|
+
|
21
|
+
|
22
|
+
conditions:
|
23
|
+
|
24
|
+
parameters:
|
25
|
+
gatgets_path:
|
26
|
+
type: dependence
|
27
|
+
value: variable/gatgets_path
|
28
|
+
gatget_arg_name:
|
29
|
+
type: dependence
|
30
|
+
value: arguments/gatget_name
|
31
|
+
launcher_path:
|
32
|
+
type: dependence
|
33
|
+
value: arguments/launcher_path
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
actions:
|
39
|
+
copy_launcher:
|
40
|
+
type: shell_command
|
41
|
+
flags: [ launcher_exists ]
|
42
|
+
syntax: cp {{gatgets_path}}/{{gatget_arg_name}}/launcher.rb {{launcher_path}}/gatget_{{gatget_arg_name}}
|
43
|
+
list_system_gatgets:
|
44
|
+
type: ruby_method
|
45
|
+
flags: [ ]
|
46
|
+
|
47
|
+
|
48
|
+
operations:
|
49
|
+
list:
|
50
|
+
description: 'List avalaible system gatgets'
|
51
|
+
users: [ ]
|
52
|
+
programs: [ ]
|
53
|
+
arguments: [ ]
|
54
|
+
folders: [ ]
|
55
|
+
helpers: [ ]
|
56
|
+
conditions: [ ]
|
57
|
+
actions: [ list_system_gatgets ]
|
58
|
+
outputs: [ template ]
|
59
|
+
onfail: [ ]
|
60
|
+
|
61
|
+
use:
|
62
|
+
description: 'Create launcher for a defined gatget'
|
63
|
+
users: [ ]
|
64
|
+
programs: [ ]
|
65
|
+
arguments: [ gatget_name, launcher_path ]
|
66
|
+
folders: [ ]
|
67
|
+
helpers: [ valid_gatget_name ]
|
68
|
+
conditions: [ ]
|
69
|
+
actions: [ copy_launcher ]
|
70
|
+
outputs: [ ]
|
71
|
+
onfail: [ ]
|
@@ -0,0 +1,26 @@
|
|
1
|
+
This is the synchronization gatget.
|
2
|
+
|
3
|
+
To use it with udev, do the following:
|
4
|
+
|
5
|
+
1) Add a udev rule in a file like /etc/udev/rules.d/10-myrules.rules
|
6
|
+
|
7
|
+
KERNEL=="sd[a-z][0-9]*", SUBSYSTEM=="block", ATTR{size}=="488392002", SYMLINK+="backup_dev/%n", OPTIONS+="last_rule"
|
8
|
+
|
9
|
+
2) Add a cron job to check for the presence of the device:
|
10
|
+
|
11
|
+
# Check if the external usb drive is plugged-in, every 3 minutes, and if so, run sync
|
12
|
+
*/3 * * * * root test -b /dev/backup_dev/1 && cd /usr/local/sbin && /bin/bash gat_sync_cron.sh /dev/backup_dev/1 /dest_dir_to_mount
|
13
|
+
|
14
|
+
|
15
|
+
WARNING: If you want to log the cron output, edit /etc/crontab, do not use crontab -e as it doesn't redirect the cron output
|
16
|
+
|
17
|
+
3) Edit /usr/local/sbin/gat_sync_cron.sh to set a few values:
|
18
|
+
|
19
|
+
MINUTES_CREATED=5
|
20
|
+
MAX_HOURS_FINISHED=10
|
21
|
+
|
22
|
+
== Issues
|
23
|
+
|
24
|
+
I have not found a way of getting udev reporting me when the device is unplugged.
|
25
|
+
|
26
|
+
I have neither found a way of unplug the device by software, so to prevent the script for running continuously until the user unplugs it, I have to use a temporary file to mark the completion of the sync and avoid doing it until a number of defined hours have passed.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'gatgets/synchronization/synchronization'
|
4
|
+
|
5
|
+
class MyRsyncScript < GatgetSynchronization
|
6
|
+
end
|
7
|
+
|
8
|
+
# default options... see all options at Gatget config file GAT_ROOT + /lib/gatgets/synchronization/rsync_synchronization.yml
|
9
|
+
|
10
|
+
options = {
|
11
|
+
'gat_config' => '/etc/gat/gat.yml',
|
12
|
+
'gatget_config' => {
|
13
|
+
'folders' => { 'source' => { 'path' => '/source/path' },
|
14
|
+
'dest' => { 'path' => '/dest/path' }
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
# Launch Gatget
|
20
|
+
MyRsyncScript.launch(options, ARGV)
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
if (( $# != 2 )); then
|
4
|
+
echo "Usage: $0 DEVICE MOUNT_DIR"
|
5
|
+
exit 1
|
6
|
+
fi
|
7
|
+
|
8
|
+
DEVICE=$1
|
9
|
+
MOUNT_DIR=$2
|
10
|
+
|
11
|
+
TAG=gat_sync
|
12
|
+
logger -t $TAG Starting...
|
13
|
+
MINUTES_CREATED=5
|
14
|
+
MAX_HOURS_FINISHED=10
|
15
|
+
|
16
|
+
DONE_FLAG=/tmp/rsync_done.flag
|
17
|
+
# Check if the device is plugged in, that is, udev has created the device node
|
18
|
+
if test -b $DEVICE; then
|
19
|
+
logger -t $TAG "$DEVICE exists"
|
20
|
+
now=$(date --utc +"%s")
|
21
|
+
device_created=$(stat -c "%Z" $DEVICE)
|
22
|
+
device_minutes_created=$(( ($now-$device_created) / 60 ))
|
23
|
+
|
24
|
+
goon=1
|
25
|
+
# If $DONE_FLAG exists, the rsync has already been done, but when?
|
26
|
+
if test -f $DONE_FLAG; then
|
27
|
+
done_flag_created=$(stat -c "%Z" $DONE_FLAG)
|
28
|
+
done_flag_hours_created=$(( ($now-$done_flag_created) / 60 / 60 ))
|
29
|
+
# If the device has been created after the last rsync, do it again
|
30
|
+
if (( $device_created > $done_flag_created )); then
|
31
|
+
rm -f $DONE_FLAG
|
32
|
+
logger -t $TAG "device inserted after last rsync, so do it again..."
|
33
|
+
else
|
34
|
+
# if not, check how many hours have been passed
|
35
|
+
if (( $done_flag_hours_created < $MAX_HOURS_FINISHED)); then
|
36
|
+
logger -t $TAG "rsync already done within the past $MAX_HOURS_FINISHED hours"
|
37
|
+
goon=0
|
38
|
+
fi
|
39
|
+
fi
|
40
|
+
fi
|
41
|
+
|
42
|
+
if (( $goon=="1" )); then
|
43
|
+
# Check that the device has been created at least a few minutes ago
|
44
|
+
if (( $device_minutes_created > $MINUTES_CREATED )); then
|
45
|
+
logger -t $TAG "5 minutes have passed"
|
46
|
+
# Dir lock: if this dir exists, the process is running
|
47
|
+
if mkdir $MOUNT_DIR 2>/dev/null ; then
|
48
|
+
mount $DEVICE $MOUNT_DIR
|
49
|
+
/usr/local/sbin/gat_sync -vvvvvv do_rsync
|
50
|
+
RET=$?
|
51
|
+
umount $MOUNT_DIR
|
52
|
+
rmdir $MOUNT_DIR
|
53
|
+
logger -t $TAG "finished with exit code $RET"
|
54
|
+
if (( $RET == 0 )); then
|
55
|
+
touch $DONE_FLAG
|
56
|
+
fi
|
57
|
+
else
|
58
|
+
logger -t $TAG "gat_sync is already running..."
|
59
|
+
fi
|
60
|
+
else
|
61
|
+
rm -f $DONE_FLAG
|
62
|
+
logger -t $TAG "Waiting for $DEVICE to be up for more than $MINUTES_CREATED minutes"
|
63
|
+
fi
|
64
|
+
fi
|
65
|
+
else
|
66
|
+
logger -t $TAG "$DEVICE not found"
|
67
|
+
fi
|
68
|
+
|
69
|
+
logger -t $TAG Exiting...
|
@@ -0,0 +1,123 @@
|
|
1
|
+
=begin
|
2
|
+
This file is part of GAT: http://gat.rubyforge.org
|
3
|
+
|
4
|
+
(c) 2008-2009 A.C. Gnoxys info@gnoxys.net
|
5
|
+
|
6
|
+
GAT (Gnoxys Administration Tools) is released under the GPL License 3 or higher.
|
7
|
+
You can get a copy of the license easily at http://www.gnu.org/licenses/gpl.html.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
10
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
11
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
12
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
13
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
14
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
15
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
16
|
+
=end
|
17
|
+
|
18
|
+
# \TODO Check that the sync destination folder is inside the mounted drive
|
19
|
+
|
20
|
+
require 'gat'
|
21
|
+
|
22
|
+
GATGET_SYNCHRONIZATION_ROOT = File.expand_path(File.dirname(__FILE__))
|
23
|
+
|
24
|
+
class GatgetSynchronization < Gat::Base
|
25
|
+
|
26
|
+
def setflag_remote_backup_running
|
27
|
+
a = Gat::Action::ShellCommand.new('check_remote_backup_status', self.config['actions']['check_remote_backup_status'], self.operation)
|
28
|
+
a.execute
|
29
|
+
set_flag("flag_remote_backup_running", a.output.downcase == "running\n" )
|
30
|
+
end
|
31
|
+
|
32
|
+
def check_host_defined
|
33
|
+
allhosts = `cut -s -f 2 /etc/hosts`
|
34
|
+
required_host = get_dependence_variable("remote_host")
|
35
|
+
if not allhosts.split("\n").include?( required_host )
|
36
|
+
raise Gat::GatgetException.new( "Host #{required_host} not defined in /etc/hosts", "check_host_defined" )
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def notify_start
|
41
|
+
st_notify_email_started = get_dependence_value("static", "notify_email_started")
|
42
|
+
if st_notify_email_started && st_notify_email_started["sent_to"]
|
43
|
+
to = st_notify_email_started
|
44
|
+
end
|
45
|
+
subject = st_notify_email_started["subject"]
|
46
|
+
body = st_notify_email_started["body"]
|
47
|
+
if to.nil?
|
48
|
+
if self.config["email_config"]
|
49
|
+
to = self.config["email_config"]["send_to"]
|
50
|
+
else
|
51
|
+
raise Gat::GatgetConfigException.new("Default email config[to] is empty at gatget.config['email_config']", "run_output_email")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
subject = "Rsync started" if subject.nil?
|
55
|
+
body = "Define your own body in static.notify_email_started.body" if body.nil?
|
56
|
+
|
57
|
+
full_subject = "[GAT] [#{ self.class.name }] [#{ self.operation.name.camelize }] #{subject}"
|
58
|
+
create_and_deliver_email(to,
|
59
|
+
{ 'subject' => full_subject,
|
60
|
+
'body' => body },
|
61
|
+
self.config["email_config"]
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
# send rescue email will send a email for notification errors at do_backup operation
|
67
|
+
def onfail
|
68
|
+
|
69
|
+
unless self.config['email_config']
|
70
|
+
raise Gat::GatgetConfigException.new("Default email config is empty at gatget.config['email_config']", "run_output_email")
|
71
|
+
end
|
72
|
+
|
73
|
+
unless self.config['email_config']['send_to']
|
74
|
+
raise Gat::GatgetConfigException.new("Default email config 'send_to' is empty at gatget.config['email_config']", "run_output_email")
|
75
|
+
end
|
76
|
+
|
77
|
+
email_subject = "[GAT] [#{ self.class.name }] [#{ self.operation.name.camelize }] [FAILED]"
|
78
|
+
|
79
|
+
|
80
|
+
email_body = "Gatget #{ self.class.name } was stopped by raising of #{ self.onfail_error.class } at #{ Time.now }\n\n"
|
81
|
+
email_body << "#{ onfail_error.exit_error }"
|
82
|
+
email_body << "\n\n Errors log: \n\n #{self.logger.entries.select{ |e| e.global_type == 'error' }.map{ |e| e.inspect }.join("\n") }\n\n"
|
83
|
+
email_body << "\n\n Warning log: \n\n #{self.logger.entries.select{ |e| e.global_type == 'warning' }.map{ |e| e.inspect }.join("\n") }\n\n"
|
84
|
+
email_body << "\n\n Whole log: \n\n #{self.logger.entries.map{ |e| e.inspect }.join("\n") }"
|
85
|
+
|
86
|
+
self.create_and_deliver_email(self.config['email_config']['send_to'], { 'subject' => email_subject, 'body' => email_body }, self.config['email_config'])
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def exec_sync_oyw
|
91
|
+
hosts = get_dependence_value("static", "all_hosts")
|
92
|
+
while hosts.any?
|
93
|
+
hosts.each do |host|
|
94
|
+
opname = "sync_#{host}"
|
95
|
+
begin
|
96
|
+
a = Gat::Operation.new(opname, self.config['operations'][opname], self)
|
97
|
+
rescue
|
98
|
+
raise Gat::GatgetConfigException.new("Operation '#{opname}' not defined in yml", "exec_sync_oyw")
|
99
|
+
end
|
100
|
+
a.execute
|
101
|
+
backup_was_running = self.get_flag("flag_remote_backup_running")
|
102
|
+
if not backup_was_running
|
103
|
+
status = a.get_action("exec_remote_rsync").status
|
104
|
+
p status
|
105
|
+
if status == "ok"
|
106
|
+
hosts.delete host
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
sleep 100
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def set_parameters_for_my_host
|
115
|
+
set_dependence_variable( "remote_user", "backup" )
|
116
|
+
set_dependence_variable( "remote_folder", "/home/backup/" )
|
117
|
+
set_dependence_variable( "remote_host", "my_host" )
|
118
|
+
set_dependence_variable( "local_folder", "/home/backup/rsyncs/my_host" )
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
|