astrails-safe 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -148,8 +148,8 @@ Example configuration
148
148
  end
149
149
 
150
150
  keep do
151
- local 2
152
- s3 2
151
+ local 20
152
+ s3 30
153
153
  end
154
154
 
155
155
  mysqldump do
@@ -162,7 +162,10 @@ Example configuration
162
162
  database :blog
163
163
  database :servershape
164
164
  database :astrails_com
165
- database :secret_project_com
165
+ database :secret_project_com do
166
+ skip_tables "foo"
167
+ skip_tables ["bar", "baz"]
168
+ end
166
169
 
167
170
  end
168
171
 
@@ -189,7 +192,8 @@ Example configuration
189
192
 
190
193
  archive "blog-astrails-com" do
191
194
  files "/var/www/blog.astrails.com/"
192
- exclude ["/var/www/blog.astrails.com/log", "/var/www/blog.astrails.com/tmp"]
195
+ exclude "/var/www/blog.astrails.com/log"
196
+ exclude "/var/www/blog.astrails.com/tmp"
193
197
  end
194
198
 
195
199
  archive "astrails-com" do
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 2
4
- :patch: 4
4
+ :patch: 5
@@ -42,6 +42,7 @@ describe "tar backup" do
42
42
  archive :test1 do
43
43
  files src
44
44
  exclude "#{src}/q/w"
45
+ exclude "#{src}/q/w/e"
45
46
  end
46
47
  end
47
48
  end
@@ -74,6 +75,8 @@ describe "tar backup" do
74
75
  it "should only include qwe 1 and 2 (no 3)" do
75
76
  File.exists?("#{@test}/qwe1").should be_true
76
77
  File.exists?("#{@test}/q/qwe2").should be_true
78
+ File.exists?("#{@test}/q/w/qwe3").should be_false
79
+ File.exists?("#{@test}/q/w/e/qwe4").should be_false
77
80
  end
78
81
 
79
82
  it "should preserve file content" do
@@ -83,4 +86,4 @@ describe "tar backup" do
83
86
  end
84
87
  end
85
88
 
86
- end
89
+ end
@@ -64,4 +64,4 @@ describe Astrails::Safe::Archive do
64
64
  archive(:foo, {:files => ["foo", "bar"]}).send(:tar_files).should == "foo bar"
65
65
  end
66
66
  end
67
- end
67
+ end
@@ -181,4 +181,33 @@ describe Astrails::Safe::Config do
181
181
 
182
182
  config.to_hash.should == expected
183
183
  end
184
+
185
+ it "should make an array from multivalues" do
186
+ config = Astrails::Safe::Config::Node.new do
187
+ skip_tables "a"
188
+ skip_tables "b"
189
+ files "/foo"
190
+ files "/bar"
191
+ exclude "/foo/bar"
192
+ exclude "/foo/bar/baz"
193
+ end
194
+
195
+ expected = {
196
+ "skip_tables" => ["a", "b"],
197
+ "files" => ["/foo", "/bar"],
198
+ "exclude" => ["/foo/bar", "/foo/bar/baz"],
199
+ }
200
+
201
+ config.to_hash.should == expected
202
+ end
203
+
204
+ it "should raise error on key duplication" do
205
+ proc do
206
+ Astrails::Safe::Config::Node.new do
207
+ path "foo"
208
+ path "bar"
209
+ end
210
+ end.should raise_error(ArgumentError, "duplicate value for 'path'")
211
+ end
212
+
184
213
  end
@@ -87,21 +87,21 @@ describe Astrails::Safe::Local do
87
87
 
88
88
  describe :cleanup do
89
89
  before(:each) do
90
- @local = local
91
90
  @files = [4,1,3,2].to_a.map { |i| "/mysqldump~blog~NoW/qweqwe.#{i}" }
92
- stub(Dir).[]("/mysqldump~blog~NoW/qweqwe.*") {@files}
93
91
  stub(File).file?(anything) {true}
94
92
  stub(File).size(anything) {1}
95
93
  stub(File).unlink
96
94
  end
97
95
 
98
96
  it "should check [:keep, :local]" do
99
- @local.config[:keep][:local] = nil
97
+ @local = local(def_config.merge(:keep => {}))
100
98
  dont_allow(Dir).[]
101
99
  @local.send :cleanup
102
100
  end
103
101
 
104
102
  it "should delete extra files" do
103
+ @local = local
104
+ mock(Dir).[]("/mysqldump~blog~NoW/qweqwe.*") {@files}
105
105
  mock(File).unlink("/mysqldump~blog~NoW/qweqwe.1")
106
106
  mock(File).unlink("/mysqldump~blog~NoW/qweqwe.2")
107
107
  @local.send :cleanup
@@ -44,7 +44,7 @@ describe Astrails::Safe::S3 do
44
44
  end
45
45
 
46
46
  it "should check [:keep, :s3]" do
47
- @s3.config[:keep][:s3] = nil
47
+ @s3.config[:keep].data["s3"] = nil
48
48
  dont_allow(@s3.backup).filename
49
49
  @s3.send :cleanup
50
50
  end
@@ -67,17 +67,17 @@ describe Astrails::Safe::S3 do
67
67
  end
68
68
 
69
69
  it "should be false if bucket is missing" do
70
- @s3.config[:s3][:bucket] = nil
70
+ @s3.config[:s3].data["bucket"] = nil
71
71
  @s3.should_not be_active
72
72
  end
73
73
 
74
74
  it "should be false if key is missing" do
75
- @s3.config[:s3][:key] = nil
75
+ @s3.config[:s3].data["key"] = nil
76
76
  @s3.should_not be_active
77
77
  end
78
78
 
79
79
  it "should be false if secret is missing" do
80
- @s3.config[:s3][:secret] = nil
80
+ @s3.config[:s3].data["secret"] = nil
81
81
  @s3.should_not be_active
82
82
  end
83
83
  end
@@ -87,7 +87,7 @@ describe Astrails::Safe::S3 do
87
87
  @s3 = s3
88
88
  end
89
89
  it "should use s3/path 1st" do
90
- @s3.config[:s3][:path] = "s3_path"
90
+ @s3.config[:s3].data["path"] = "s3_path"
91
91
  @s3.config[:local] = {:path => "local_path"}
92
92
  @s3.send(:path).should == "s3_path"
93
93
  end
@@ -21,4 +21,4 @@ module Astrails
21
21
 
22
22
  end
23
23
  end
24
- end
24
+ end
@@ -4,6 +4,7 @@ module Astrails
4
4
  module Config
5
5
  class Node
6
6
  attr_reader :parent
7
+ attr_reader :data
7
8
  def initialize(parent = nil, data = {}, &block)
8
9
  @parent, @data = parent, {}
9
10
  data.each { |k, v| self[k] = v }
@@ -26,14 +27,23 @@ module Astrails
26
27
  end
27
28
  alias :[] :find
28
29
 
30
+ MULTIVALUES = %w/skip_tables exclude files/
29
31
  def set(key, value, &block)
30
- @data[key.to_s] =
31
- if value.is_a?(Hash)
32
- Node.new(self, value, &block)
32
+ if @data[key.to_s]
33
+ raise(ArgumentError, "duplicate value for '#{key}'") if value.is_a?(Hash) || !MULTIVALUES.include?(key.to_s)
34
+ end
35
+
36
+ if value.is_a?(Hash)
37
+ @data[key.to_s] = Node.new(self, value, &block)
38
+ else
39
+ raise(ArgumentError, "#{key}: no block supported for simple values") if block
40
+ if @data[key.to_s]
41
+ @data[key.to_s] = @data[key.to_s].to_a + value.to_a
33
42
  else
34
- raise(ArgumentError, "#{key}: no block supported for simple values") if block
35
- value
43
+ @data[key.to_s] = value
36
44
  end
45
+ value
46
+ end
37
47
  end
38
48
  alias :[]= :set
39
49
 
@@ -63,4 +73,4 @@ module Astrails
63
73
  end
64
74
  end
65
75
  end
66
- end
76
+ end
@@ -74,8 +74,12 @@ safe do
74
74
  # gpg do
75
75
  # password "custom-production-pass"
76
76
  # end
77
-
78
- # skip_tables [:logger_exceptions, :request_logs] # skip those tables during backup
77
+ # # skip those tables during backup
78
+ # # you can pass an array
79
+ # skip_tables [:logger_exceptions, :request_logs]
80
+ # # or pass them all separately
81
+ # skip_tables :test1
82
+ # skip_tables :test2
79
83
  # end
80
84
 
81
85
  end
@@ -99,12 +103,16 @@ safe do
99
103
  # archive "git-repositories" do
100
104
  # # files and directories to backup
101
105
  # files "/home/git/repositories"
106
+ # # can have more then one 'files' lines or/and use an array
107
+ # files ["/home/dev/work/foo", "/home/dev/work/bar"]
102
108
  # end
103
109
 
104
110
  # archive "etc-files" do
105
111
  # files "/etc"
106
112
  # # exlude those files/directories
107
113
  # exclude "/etc/puppet/other"
114
+ # # can have multiple 'exclude' lines or/and use an array
115
+ # exclude ["/etc/tmp/a", "/etc/tmp/b"]
108
116
  # end
109
117
 
110
118
  # archive "dot-configs" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: astrails-safe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Astrails Ltd.
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-10-09 00:00:00 +02:00
13
+ date: 2009-10-20 00:00:00 +02:00
14
14
  default_executable: astrails-safe
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency