BackupMan 0.1.4 → 0.1.5
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/BackupMan.gemspec +1 -1
- data/VERSION +1 -1
- data/features/dsl_parameters.feature +1 -3
- data/features/step_definitions/dsl_parameters_steps.rb +1 -2
- data/lib/backup_man/backup.rb +61 -15
- data/lib/backup_man/cli.rb +1 -1
- data/lib/backup_man/dsl.rb +2 -65
- data/lib/backup_man/mysql.rb +4 -6
- data/lib/backup_man/rsync.rb +3 -5
- data/lib/backup_man/tar.rb +4 -6
- metadata +2 -2
data/BackupMan.gemspec
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
@@ -13,23 +13,21 @@ Feature: The DSL supports various parameters
|
|
13
13
|
| Tar | onlyif, backup, to, user, host, filename, options | ok |
|
14
14
|
| Mysql | onlyif, backup, to, user, host, filename, options | ok |
|
15
15
|
| Rsync | onlyif, backup, to, user, host, options | ok |
|
16
|
-
| Tidy | onlyif, directory | ok |
|
17
16
|
|
18
17
|
Scenarios: full set, but invalid parameters are present
|
19
18
|
| task | parameters | result |
|
20
19
|
| Tar | onlyif, backup, to, user, host, filename, options, invalid_parameter | fatal "undefined method `invalid_parameter'" |
|
21
20
|
| Mysql | onlyif, backup, to, user, host, filename, options, invalid_parameter | fatal "undefined method `invalid_parameter'" |
|
22
21
|
| Rsync | onlyif, backup, to, user, host, options, invalid_parameter | fatal "undefined method `invalid_parameter'" |
|
23
|
-
| Tidy | onlyif, directory, invalid_parameter | fatal "undefined method `invalid_parameter'" |
|
24
22
|
|
25
23
|
Scenarios: minimal set, all required parameters are provided
|
26
24
|
| task | parameters | result |
|
27
25
|
| Tar | backup | ok |
|
28
26
|
| Mysql | | ok |
|
29
27
|
| Rsync | backup | ok |
|
30
|
-
| Tidy | | ok |
|
31
28
|
|
32
29
|
Scenarios: one required parameter is missing
|
33
30
|
| task | parameters | result |
|
34
31
|
| Tar | onlyif, to, user, host, filename, options | error "A required parameter is missing: backup" |
|
35
32
|
| Rsync | onlyif, to, user, host, options | error "A required parameter is missing: backup" |
|
33
|
+
|
data/lib/backup_man/backup.rb
CHANGED
@@ -45,32 +45,78 @@ module BackupMan
|
|
45
45
|
# because the default values are not available at that time;
|
46
46
|
def set_defaults
|
47
47
|
@data_sources = [] unless @data_sources
|
48
|
-
@backup_directory =
|
48
|
+
@backup_directory = "#{BackupMan.instance.destdir}/#{@name}" unless @backup_directory
|
49
49
|
@onlyif = "true" if @onlyif.nil?
|
50
50
|
@user = 'root' unless @user
|
51
51
|
@host = @name unless @host
|
52
52
|
end
|
53
|
-
|
54
|
-
#
|
55
|
-
#
|
56
|
-
def
|
57
|
-
|
53
|
+
|
54
|
+
# yields the block which comes from the DSL configuration file; also
|
55
|
+
# registers the new backup configuration with {BackupMan}
|
56
|
+
def initialize( name )
|
57
|
+
@name = name
|
58
|
+
yield(self) if block_given?
|
59
|
+
BackupMan.instance.register_backup( self )
|
58
60
|
end
|
59
61
|
|
62
|
+
# calling this actually runs the backup; DO NOT override this; override
|
63
|
+
# _run instead
|
64
|
+
def run
|
65
|
+
log_begin_of_run
|
66
|
+
set_defaults
|
67
|
+
debug_log_dsl_info
|
68
|
+
unless missing_required_parameters.empty?
|
69
|
+
Log.error( "#{self}: A required parameter is missing: #{missing_required_parameters.join ' '}")
|
70
|
+
return
|
71
|
+
end
|
72
|
+
onlyif = eval( @onlyif )
|
73
|
+
Log.debug( "onlyif = { #{@onlyif} } evaluates #{onlyif}" )
|
74
|
+
if onlyif
|
75
|
+
unless @backup_directory
|
76
|
+
Log.error( "#{self}: No backup directory. Don't know where to store all this stuff.")
|
77
|
+
else
|
78
|
+
FileUtils.mkdir_p @backup_directory
|
79
|
+
_run
|
80
|
+
end
|
81
|
+
else
|
82
|
+
Log.info( "#{self}: Preconditions for backup run not fulfilled.")
|
83
|
+
end
|
84
|
+
log_end_of_run
|
85
|
+
end
|
86
|
+
|
87
|
+
# @return [String]
|
88
|
+
def to_s
|
89
|
+
"#{self.class} #{self.name}"
|
90
|
+
end
|
91
|
+
|
92
|
+
|
60
93
|
|
61
94
|
private
|
62
|
-
|
95
|
+
|
96
|
+
# @abstract override this to implement the actual backup commands
|
63
97
|
def _run
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
98
|
+
throw "Hey. Cannot run just 'Backup'."
|
99
|
+
end
|
100
|
+
|
101
|
+
# @return [Array of Strings] of missing parameters
|
102
|
+
def missing_required_parameters
|
103
|
+
missing = []
|
104
|
+
self.class.dsl_methods.each do |name, var, mandatory|
|
105
|
+
missing << name if mandatory && self.instance_variable_get("@#{var}").empty?
|
71
106
|
end
|
107
|
+
missing
|
72
108
|
end
|
73
|
-
|
109
|
+
|
110
|
+
# not used acutally
|
111
|
+
def log_begin_of_run
|
112
|
+
Log.info( "Starting #{self.class} run for #{@name}." )
|
113
|
+
end
|
114
|
+
|
115
|
+
# simply logs that the program terminates
|
116
|
+
def log_end_of_run
|
117
|
+
Log.info( "Finished #{self.class} run for #{@name}." )
|
118
|
+
end
|
119
|
+
|
74
120
|
# @return [String] the ssh command string including user@host
|
75
121
|
def ssh_connect_cmd
|
76
122
|
"#{BackupMan.instance.ssh_app} #{@user}@#{@host}"
|
data/lib/backup_man/cli.rb
CHANGED
data/lib/backup_man/dsl.rb
CHANGED
@@ -16,14 +16,6 @@ module BackupMan
|
|
16
16
|
host_class.extend(ClassMethods)
|
17
17
|
end
|
18
18
|
|
19
|
-
# yields the block which comes from the DSL configuration file; also
|
20
|
-
# registers the new backup configuration with {BackupMan}
|
21
|
-
def initialize( name )
|
22
|
-
@name = name
|
23
|
-
yield(self) if block_given?
|
24
|
-
BackupMan.instance.register_backup( self )
|
25
|
-
end
|
26
|
-
|
27
19
|
def debug_log_dsl_info
|
28
20
|
Log.debug( "Job settings:")
|
29
21
|
self.class.dsl_methods.each do |method, var|
|
@@ -31,61 +23,6 @@ module BackupMan
|
|
31
23
|
end
|
32
24
|
end
|
33
25
|
|
34
|
-
# calling this actually runs the backup/task; DO NOT override this; override
|
35
|
-
# _run instead
|
36
|
-
def run
|
37
|
-
log_begin_of_run
|
38
|
-
set_defaults
|
39
|
-
debug_log_dsl_info
|
40
|
-
unless missing_required_parameters.empty?
|
41
|
-
Log.error( "#{self}: A required parameter is missing: #{missing_required_parameters.join ' '}")
|
42
|
-
return
|
43
|
-
end
|
44
|
-
onlyif = eval( @onlyif )
|
45
|
-
Log.debug( "onlyif = { #{@onlyif} } evaluates #{onlyif}" )
|
46
|
-
if onlyif
|
47
|
-
_run
|
48
|
-
else
|
49
|
-
Log.info( "#{self}: Preconditions for backup run not fulfilled.")
|
50
|
-
end
|
51
|
-
log_end_of_run
|
52
|
-
end
|
53
|
-
|
54
|
-
# @return [String]
|
55
|
-
def to_s
|
56
|
-
"#{self.class} #{self.name}"
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
# @abstract override this to implement the actual backup commands
|
61
|
-
def _run
|
62
|
-
throw "Hey. Cannot run just 'Backup'."
|
63
|
-
end
|
64
|
-
private :_run
|
65
|
-
|
66
|
-
# @return [Array of Strings] of missing parameters
|
67
|
-
def missing_required_parameters
|
68
|
-
missing = []
|
69
|
-
self.class.dsl_methods.each do |name, var, mandatory|
|
70
|
-
missing << name if mandatory && self.instance_variable_get("@#{var}").empty?
|
71
|
-
end
|
72
|
-
missing
|
73
|
-
end
|
74
|
-
private :missing_required_parameters
|
75
|
-
|
76
|
-
# not used acutally
|
77
|
-
def log_begin_of_run
|
78
|
-
Log.info( "Starting #{self.class} run for #{@name}." )
|
79
|
-
end
|
80
|
-
private :log_begin_of_run
|
81
|
-
|
82
|
-
# simply logs that the program terminates
|
83
|
-
def log_end_of_run
|
84
|
-
Log.info( "Finished #{self.class} run for #{@name}." )
|
85
|
-
end
|
86
|
-
private :log_end_of_run
|
87
|
-
|
88
|
-
|
89
26
|
module ClassMethods
|
90
27
|
|
91
28
|
# @param [String] name
|
@@ -93,7 +30,7 @@ module BackupMan
|
|
93
30
|
# @param [Boolean] mandatory, true if this var is a required parameter
|
94
31
|
def def_dsl( name, var = name, mandatory = false )
|
95
32
|
class_eval( %Q{
|
96
|
-
def #{name}( #{var}
|
33
|
+
def #{name}( #{var} )
|
97
34
|
@#{var} = #{var}
|
98
35
|
end
|
99
36
|
})
|
@@ -122,7 +59,7 @@ module BackupMan
|
|
122
59
|
@dsl_methods
|
123
60
|
end
|
124
61
|
|
62
|
+
|
125
63
|
end # ClassMethods
|
126
|
-
|
127
64
|
end #DSL
|
128
65
|
end #BackupMan
|
data/lib/backup_man/mysql.rb
CHANGED
@@ -14,15 +14,13 @@ module BackupMan
|
|
14
14
|
|
15
15
|
def set_defaults
|
16
16
|
super
|
17
|
-
@filename = "#{Date.today}-mysqlfull.sql.gz"
|
18
|
-
@options = '--all-databases -u root'
|
17
|
+
@filename = "#{Date.today}-mysqlfull.sql.gz" unless @filename
|
18
|
+
@options = '--all-databases -u root' unless @options
|
19
19
|
end
|
20
20
|
|
21
21
|
def _run
|
22
|
-
|
23
|
-
|
24
|
-
Command.new("#{ssh_connect_cmd} '#{remote_cmd} | gzip' > '#{@backup_directory}/#{@filename}'").run
|
25
|
-
end
|
22
|
+
remote_cmd = "mysqldump #{@options}"
|
23
|
+
Command.new("#{ssh_connect_cmd} '#{remote_cmd} | gzip' > '#{@backup_directory}/#{@filename}'").run
|
26
24
|
end
|
27
25
|
|
28
26
|
# returns true if the backup already exists
|
data/lib/backup_man/rsync.rb
CHANGED
@@ -13,14 +13,12 @@ module BackupMan
|
|
13
13
|
def set_defaults
|
14
14
|
@backup_directory = "#{BackupMan.instance.destdir}/#{@name}/rsync" unless @backup_directory
|
15
15
|
super
|
16
|
-
@options = "-azR --delete"
|
16
|
+
@options = "-azR --delete" unless @options
|
17
17
|
end
|
18
18
|
|
19
19
|
def _run
|
20
|
-
|
21
|
-
@
|
22
|
-
Command.new("rsync #{@options} -e '#{BackupMan.instance.ssh_app}' '#{@user}@#{@host}:#{dir}' '#{@backup_directory}'").run
|
23
|
-
end
|
20
|
+
@data_sources.each do |dir|
|
21
|
+
Command.new("rsync #{@options} -e '#{BackupMan.instance.ssh_app}' '#{@user}@#{@host}:#{dir}' '#{@backup_directory}'").run
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
data/lib/backup_man/tar.rb
CHANGED
@@ -15,15 +15,13 @@ module BackupMan
|
|
15
15
|
|
16
16
|
def set_defaults
|
17
17
|
super
|
18
|
-
@filename = "#{Date.today}-files.tgz"
|
19
|
-
@options = "zP"
|
18
|
+
@filename = "#{Date.today}-files.tgz" unless @filename
|
19
|
+
@options = "zP" unless @options
|
20
20
|
end
|
21
21
|
|
22
22
|
def _run
|
23
|
-
|
24
|
-
|
25
|
-
Command.new("#{ssh_connect_cmd} #{remote_cmd} > '#{@backup_directory}/#{@filename}'").run
|
26
|
-
end
|
23
|
+
remote_cmd = "tar -c#{@options}f - ", @data_sources.join(" ")
|
24
|
+
Command.new("#{ssh_connect_cmd} #{remote_cmd} > '#{@backup_directory}/#{@filename}'").run
|
27
25
|
end
|
28
26
|
|
29
27
|
# returns true if the backup already exists
|