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 CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{BackupMan}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Markus Strauss"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
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
+
@@ -7,8 +7,7 @@ def defaults
7
7
  "user" => "'user'",
8
8
  "host" => "'host'",
9
9
  "filename" => "'filename'",
10
- "options" => "'options'",
11
- "directory" => "'directory'"
10
+ "options" => "'options'"
12
11
  }
13
12
  end
14
13
 
@@ -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 = Backup.make_default_backup_directory(@name) unless @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
- # DRY method for creating the default backup directory. Also used for
55
- # creating the default tidy directory.
56
- def self.make_default_backup_directory( name )
57
- "#{BackupMan.instance.destdir}/#{name}"
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
- # checking if we have the backup_directory
65
- unless @backup_directory
66
- Log.error( "#{self}: No backup directory. Don't know where to store all this stuff.")
67
- return false
68
- else
69
- FileUtils.mkdir_p @backup_directory
70
- return true
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}"
@@ -6,7 +6,7 @@ require_relative 'log'
6
6
  require_relative 'tar'
7
7
  require_relative 'rsync'
8
8
  require_relative 'mysql'
9
- require_relative 'tidy'
9
+
10
10
 
11
11
  module BackupMan
12
12
  class CLI
@@ -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} = true )
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
@@ -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
- if super
23
- remote_cmd = "mysqldump #{@options}"
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
@@ -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
- if super
21
- @data_sources.each do |dir|
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
 
@@ -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
- if super
24
- remote_cmd = "tar -c#{@options}f - ", @data_sources.join(" ")
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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Markus Strauss