dated_backup 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,17 +1,27 @@
1
1
  trunk:
2
+
3
+ = Rel 0.2.1
4
+ * Rakfile's redundancies removed and generally cleaned up
5
+ * Regression test finally fixed String#to_time bug
6
+ * Error raising on String#to_time
7
+ * Testing added for bin/dbackup
8
+ * Errors now subclass from StandardError (not RuntimeError)
9
+ * Time#each_day_in_month added
10
+
11
+ = Rel 0.2
2
12
  [2007.08.01]
3
- - many misc. bug fixes
4
- - documentation added in README file
5
- - Backup Deletion now seems to work (almost too well)
6
- - warnings turned off for DSL
13
+ * many misc. bug fixes
14
+ * documentation added in README file
15
+ * Backup Deletion now seems to work (almost too well)
16
+ * warnings turned off for DSL
7
17
 
8
18
  [2007.07.21]
9
- - removed dependency on GNU cp, so now we can DatedBackup on Mac OS X
10
- - outputting of deleted directories
11
- - fixed small bugs
19
+ * removed dependency on GNU cp, so now we can DatedBackup on Mac OS X
20
+ * outputting of deleted directories
21
+ * fixed small bugs
12
22
 
13
23
  [2007.07.25]
14
- - ExecutionContext class added, so now the separate parts of the DSL
24
+ * ExecutionContext class added, so now the separate parts of the DSL
15
25
  can execute in separate contexts. The Execution Contexts
16
26
  will execute the DSL in an anonymous class + instance, so methods
17
27
  used to run the DSL do not need be included. The DSL's themselves
@@ -19,22 +29,23 @@ trunk:
19
29
  Work still needs to be done on calling these, both from the initial
20
30
  call in /bin, and later on in the DatedBackup class.
21
31
 
22
- - Any number of scripts can now be passed to the dbackup command line
32
+ * Any number of scripts can now be passed to the dbackup command line
23
33
  utility. So specify the scripts one after another:
24
34
  dbackup script1 script2 script3
25
35
 
26
36
  [2007.07.20]
27
- - Added basic DSL configuration, so no more rake for config files
37
+ * Added basic DSL configuration, so no more rake for config files
28
38
  Documentation via Rake, Rcov, and the spec reports are now
29
39
  available in doc/
30
40
  specs have been added, and code coverage is now at 100%
31
41
 
32
42
  [2007.07.15]
33
- - YAML support. Now all configuration files are written in yaml, and
43
+ * YAML support. Now all configuration files are written in yaml, and
34
44
  should be loaded by running dbackup config_file.yaml
35
45
 
36
46
  [2007.07.12]
37
- - Command line runner, dbackup added to bin. Scripts can now be called
47
+ * Command line runner, dbackup added to bin. Scripts can now be called
38
48
  with the dbackup script_name. Scripts no longer have to include
39
49
  the requirement of the gem, be executable, or end in .rb syntax.
40
50
 
51
+ = 0.1
data/README CHANGED
@@ -22,12 +22,12 @@ option to simulate the hard-link method.
22
22
 
23
23
  == Backup Assumptions
24
24
 
25
- * Your backup *server* is POSIX compliant (a modern day UNIX - Linux, *BSD, Mac OS X)
26
- * You would like to perform incremental snapshots with timestamps
25
+ * Your backup *server* is POSIX compliant (a modern day UNIX - Linux, *BSD, Mac OS X)
26
+ * You would like to perform incremental snapshots with timestamps
27
27
 
28
28
  = Installation:
29
29
 
30
- * sudo gem install 'datedbackup' --include-dependencies
30
+ * sudo gem install 'dated_backup' --include-dependencies
31
31
 
32
32
  == Dependencies
33
33
 
@@ -36,7 +36,8 @@ Dated Backup has the following dependencies:
36
36
  * Ruby
37
37
  * Rubygems
38
38
  * Rails' 'ActiveSupport' gem
39
- * A copy of rsync, which supports the --link-dest option.
39
+ * A copy of rsync, which supports the --link-dest option (version 2.5.7 or greater).
40
+ * A POSIX-like (Linux, BSD*, Mac OS X, Solaris) OS to store the backups
40
41
 
41
42
  Rsync is not required on the machine to be backed up - only on the machine which stores
42
43
  the backup.
@@ -49,11 +50,11 @@ directory (or remote location), and the local destination directory. These two
49
50
  parameters are the only requirements for a backup configuration file to be valid.
50
51
  The script can be run with the executable dbackup:
51
52
 
52
- % dbackup my_script
53
+ <tt>$ dbackup my_script</tt>
53
54
 
54
55
  Other scripts can be run sequentially by listing them in order:
55
56
 
56
- % dbackup my_first_script my_second_script
57
+ <tt>$ dbackup my_first_script my_second_script</tt>
57
58
 
58
59
  All of the configuration occurs in the configuration file.
59
60
 
@@ -90,14 +91,14 @@ feed into rsync. It too, is optional.
90
91
 
91
92
  It is very convenient, and often necessary to perform something before or after a backup script
92
93
  runs. Any actions must be inside a 'before' or 'after' block:
94
+
95
+ before do
96
+ # ...some before action here
97
+ end
93
98
 
94
- before do
95
- ...some before action here
96
- end
97
-
98
- after {
99
- ..some other action here
100
- }
99
+ after {
100
+ # ...some other action here
101
+ }
101
102
 
102
103
  You have the pick of do...end, or { ... }, thanks to Matz. No doubt, this will be familiar to any
103
104
  Ruby programmer.
@@ -115,13 +116,13 @@ directory.
115
116
  The remove_old block takes several different natural language time forms. All of the statements inside
116
117
  a remove_old block must begin with 'keep'. An example would work best to illustrate how to use this:
117
118
 
118
- after do
119
- remove_old do
120
- keep this months backups
121
- keep last months backups
122
- keep monthly backups
119
+ after do
120
+ remove_old do
121
+ keep this months backups
122
+ keep last months backups
123
+ keep monthly backups
124
+ end
123
125
  end
124
- end
125
126
 
126
127
  This says the following: After the backup runs, remove all backups that do not conform to the criteria
127
128
  given. The first line will save all backups which have occured this month, regardless of what time
@@ -135,14 +136,14 @@ according to the month)
135
136
  A few things should be notice here: These config files read very easily, so don't let them fool you.
136
137
  They will delete your backups, forever lost. I've already burned myself with the following:
137
138
 
138
- after {
139
- remove_old {
140
- keep this weeks backups
141
- keep last weeks backups
142
- keep weekly backups from this month # or: keep this months weekly backups
143
- keep monthly backups # or: keep all monthly backups
139
+ after {
140
+ remove_old {
141
+ keep this weeks backups
142
+ keep last weeks backups
143
+ keep weekly backups from this month # or: keep this months weekly backups
144
+ keep monthly backups # or: keep all monthly backups
145
+ }
144
146
  }
145
- }
146
147
 
147
148
  After a month of backups, the month rolled over, and the next backup on the first of the month deleted
148
149
  all backups, except the one just performed, and the one from the last day of the month before.
@@ -175,12 +176,19 @@ The config file shown above should give you some hints on the possibilities. He
175
176
 
176
177
  Some other keywords, such as 'yesterday', and 'today' will be added in subsequent releases.
177
178
 
178
- And finally, a final warning: If a remove_old block is given, but no keep rules are given, every backup
179
+ And finally, a warning: If a remove_old block is given, but no keep rules are given, every backup
179
180
  will be deleted! This may change in a subsequent release, but for now, beware!
180
181
 
181
182
 
183
+ = License
184
+
185
+ Dated Backup is released under the GNU GPL. This means that you can use it for no charge as an individual
186
+ or business. It also means that if you are a hacker, you can modify it at your will.
187
+ The license is attached under 'COPYRIGHT'.
188
+
189
+
182
190
  = Contributions
183
191
 
184
192
  If you are interested in contributing code or documentation, please contact me,
185
- Scott Taylor, at scott AT railsnewbie DOT com.
193
+ Scott Taylor, at scott AT railsnewbie DOT com. I'm also up for hire (hint, hint).
186
194
 
data/RELEASES CHANGED
@@ -1,21 +1,23 @@
1
+ = 0.2.1
2
+
3
+ * Major DSL/Time bug-fix (String#to_time bug, fixed in revision 169)
4
+ * Documentation updates
1
5
 
2
6
  = 0.2.0
3
- =======
4
7
 
5
- - A Script Runner/binary has been added (dbackup)
6
- - A DSL has been added for configuring backups
7
- - Removal of old backups can now be specified in the DSL, using
8
+ * A Script Runner/binary has been added (dbackup)
9
+ * A DSL has been added for configuring backups
10
+ * Removal of old backups can now be specified in the DSL, using
8
11
  natural language forms
9
- - Before + After actions for the script runner
10
- - RSpec + RCov = Bug free code
11
- - Documentation added in the README file
12
- - Developer Documentation in Rake and RSpec Report
13
- - A series of example config files have been attached for Documentation
14
- - Root backup directories are now created automatically
15
- - Removed dependency on GNU's cp, so now this utility can be used
12
+ * Before + After actions in the DSL
13
+ * RSpec + RCov = Bug free code
14
+ * Documentation added in the README file
15
+ * Developer Documentation in Rake and RSpec Report
16
+ * A series of example config files have been attached for Documentation
17
+ * Root backup directories are now created automatically
18
+ * Removed dependency on GNU's cp, so now this utility can be used
16
19
  on any *NIX, including Mac OS X
17
20
 
18
21
  = 0.1.0
19
- =======
20
22
 
21
- - Initial Release
23
+ * Initial Release
@@ -19,4 +19,4 @@
19
19
 
20
20
  require File.dirname(__FILE__) + "/../lib/dated_backup"
21
21
 
22
- DatedBackup::ExecutionContext.new :main, *ARGV
22
+ DatedBackup::ExecutionContext.new(:main, *ARGV)
@@ -1,4 +1,4 @@
1
- # A script to back up etc, locally, in /root/etc_backup
1
+ # A script to back up /etc locally in /root/etc_backup
2
2
 
3
3
  source '/etc'
4
4
  destination '/root/etc_backup'
@@ -46,8 +46,7 @@ module DatedBackup
46
46
  private
47
47
 
48
48
  def generate_backup_filename
49
- timestamp = Time.now.strftime "%Y-%m-%d-%Hh-%Mm-%Ss"
50
- "#{@backup_root}/#{timestamp}"
49
+ "#{@backup_root}/#{Time.now.to_string}"
51
50
  end
52
51
 
53
52
  protected
@@ -2,6 +2,14 @@
2
2
  module DatedBackup
3
3
  class ExecutionContext
4
4
 
5
+ module ExecutionContextHelper
6
+ def anonymous_instance_loading_module(mod)
7
+ klass = Class.new
8
+ klass.send(:include, mod)
9
+ klass.new
10
+ end
11
+ end
12
+
5
13
  def initialize(name, *params, &blk)
6
14
  DatedBackup::Warnings.execute_silently do
7
15
  if name == :main
@@ -16,10 +24,11 @@ module DatedBackup
16
24
 
17
25
  class Main
18
26
  class << self
27
+
28
+ include ExecutionContextHelper
29
+
19
30
  def load(filename)
20
- klass = Class.new
21
- klass.send(:include, DSL::Main)
22
- instance = klass.new
31
+ instance = anonymous_instance_loading_module(DSL::Main)
23
32
 
24
33
  File.open filename, "r" do |file|
25
34
  instance.instance_eval file.read
@@ -37,17 +46,16 @@ module DatedBackup
37
46
  end
38
47
 
39
48
  class Around
49
+
50
+ include ExecutionContextHelper
51
+
40
52
  def initialize(around=self, &blk)
41
53
  around.instance_eval &blk
42
54
  end
43
55
 
44
56
  def remove_old(&blk)
45
- klass = Class.new
46
- klass.send(:include, DSL::TimeExtensions)
47
- instance = klass.new
48
-
57
+ instance = anonymous_instance_loading_module(DSL::TimeExtensions)
49
58
  instance.instance_eval &blk
50
-
51
59
  Core::BackupRemover.remove!(Main.instance.backup_root, instance.kept)
52
60
  end
53
61
  end
@@ -3,4 +3,5 @@ require File.dirname(__FILE__) + "/extensions/array"
3
3
  require File.dirname(__FILE__) + "/extensions/time"
4
4
  require File.dirname(__FILE__) + "/extensions/error"
5
5
  require File.dirname(__FILE__) + "/extensions/time_symbol"
6
- require File.dirname(__FILE__) + "/extensions/string"
6
+ require File.dirname(__FILE__) + "/extensions/string"
7
+ require File.dirname(__FILE__) + "/extensions/reverse_sorted_unique_array"
@@ -12,16 +12,3 @@ class Array
12
12
  DatedBackup::Core::BackupSet.new(self)
13
13
  end
14
14
  end
15
-
16
- # A subclass of Array, but it calls uniq!, sort!, and reverse!
17
- # (in that order) after the instance is created
18
- class ReverseSortedUniqueArray < Array
19
-
20
- def initialize *args, &blk
21
- super *args, &blk
22
- uniq!
23
- sort!
24
- reverse!
25
- end
26
-
27
- end
@@ -1,10 +1,12 @@
1
1
 
2
- class TimeSymbolError < RuntimeError; end
3
-
4
- class DatedBackupError < RuntimeError; end
5
-
6
- class DirectoryError < DatedBackupError; end
7
- class InvalidDirectoryError < DirectoryError; end
8
- class NoBlockGiven < DatedBackupError; end
9
- class InvalidKeyError < DatedBackupError; end
2
+ # Base Class Errors
3
+ class TimeSymbolError < StandardError; end
4
+ class StringToTimeConversionError < StandardError; end
5
+
6
+ # DatedBackup Errors
7
+ class DatedBackupError < StandardError; end
8
+ class DirectoryError < DatedBackupError; end
9
+ class InvalidDirectoryError < DirectoryError; end
10
+ class NoBlockGiven < DatedBackupError; end
11
+ class InvalidKeyError < DatedBackupError; end
10
12
 
@@ -0,0 +1,14 @@
1
+
2
+
3
+ # A subclass of Array, but it calls uniq!, sort!, and reverse!
4
+ # (in that order) after the instance is created
5
+ class ReverseSortedUniqueArray < Array
6
+
7
+ def initialize *args, &blk
8
+ super *args, &blk
9
+ uniq!
10
+ sort!
11
+ reverse!
12
+ end
13
+
14
+ end
@@ -1,8 +1,21 @@
1
1
 
2
2
  class String
3
+ # This must take a time in a format similar to the
4
+ # format generated the Time.to_string. The format should be like this:
5
+ # .+2007-07-01-00m-00h-00s.+
6
+ # Any number of charachters can come before or after the time format
7
+ # string. A TimeException will be raised if the string does not
8
+ # conform to the time format.
3
9
  def to_time
4
- string = self.dup
5
- string.sub!(/^(.*?)([\d\-\h\m\s]+)(.*?)$/) { $2 }
6
- Time.gm(*(string.split('-').map { |element| element.sub /h|m|s/, ''}))
10
+ if self =~ /(\d{4}\-\d{2}-\d{2}-\d{2}h\-\d{2}m-\d{2}s)/
11
+ begin
12
+ time_array = $1.gsub(/h|m|s/, '').split '-'
13
+ Time.gm(*time_array)
14
+ rescue
15
+ raise StringToTimeConversionError, "The string cannot be a converted to a valid time (it is out of range)"
16
+ end
17
+ else
18
+ raise StringToTimeConversionError, "The string cannot be converted to a time object"
19
+ end
7
20
  end
8
21
  end
@@ -42,6 +42,20 @@ class Time
42
42
  beginning_of_week...end_of_week
43
43
  end
44
44
 
45
+ def each_day_in_month
46
+ 1.upto(days_in_month) do |day_num|
47
+ yield beginning_of_month + (day_num - 1).day
48
+ end
49
+ end
50
+
51
+ def days_in_month
52
+ self.class.days_in_month(self.month, self.year)
53
+ end
54
+
55
+ def to_string
56
+ strftime("%Y-%m-%d-%Hh-%Mm-%Ss")
57
+ end
58
+
45
59
  end
46
60
 
47
61
  class Fixnum
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: dated_backup
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2007-08-02 00:00:00 -04:00
6
+ version: 0.2.1
7
+ date: 2007-08-06 00:00:00 -04:00
8
8
  summary: Incremental Dated Backups Using Rsync
9
9
  require_paths:
10
10
  - lib
@@ -47,6 +47,7 @@ files:
47
47
  - lib/dated_backup/extensions
48
48
  - lib/dated_backup/extensions/array.rb
49
49
  - lib/dated_backup/extensions/error.rb
50
+ - lib/dated_backup/extensions/reverse_sorted_unique_array.rb
50
51
  - lib/dated_backup/extensions/string.rb
51
52
  - lib/dated_backup/extensions/time.rb
52
53
  - lib/dated_backup/extensions/time_symbol.rb