astrails-safe 0.1.9 → 0.1.10

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/Rakefile CHANGED
@@ -28,7 +28,7 @@ end
28
28
 
29
29
  Micronaut::RakeTask.new(:rcov) do |examples|
30
30
  examples.pattern = 'examples/**/*_example.rb'
31
- examples.rcov_opts = '-Ilib -Iexamples'
31
+ examples.rcov_opts = '-Ilib -Iexamples -iastrails -x\/gems\/'
32
32
  examples.rcov = true
33
33
  end
34
34
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 9
4
+ :patch: 10
@@ -5,6 +5,9 @@ describe Astrails::Safe::Local do
5
5
  {
6
6
  :local => {
7
7
  :path => "/:kind~:id~:timestamp"
8
+ },
9
+ :keep => {
10
+ :local => 2
8
11
  }
9
12
  }
10
13
  end
@@ -34,15 +37,15 @@ describe Astrails::Safe::Local do
34
37
  end
35
38
  end
36
39
 
37
- describe :prefix do
40
+ describe :path do
38
41
  it "should raise RuntimeError when no path" do
39
42
  lambda {
40
- local({}).send :prefix
43
+ local({}).send :path
41
44
  }.should raise_error(RuntimeError, "missing :local/:path")
42
45
  end
43
46
 
44
47
  it "should use local/path" do
45
- local.send(:prefix).should == "/mysqldump~blog~NoW"
48
+ local.send(:path).should == "/mysqldump~blog~NoW"
46
49
  end
47
50
  end
48
51
 
@@ -50,7 +53,7 @@ describe Astrails::Safe::Local do
50
53
  before(:each) do
51
54
  @local = local
52
55
  stub(@local).system
53
- stub(@local).path {"file-path"}
56
+ stub(@local).full_path {"file-path"}
54
57
  stub(FileUtils).mkdir_p
55
58
  end
56
59
 
@@ -77,6 +80,25 @@ describe Astrails::Safe::Local do
77
80
  end
78
81
 
79
82
  describe :cleanup do
80
- it "should have test"
83
+ before(:each) do
84
+ @local = local
85
+ @files = [4,1,3,2].to_a.map { |i| "aaaaa#{i}" }
86
+ stub(Dir).[](anything) {@files}
87
+ stub(File).file?(anything) {true}
88
+ stub(File).size(anything) {1}
89
+ stub(File).unlink
90
+ end
91
+
92
+ it "should check [:keep, :local]" do
93
+ @local.config[:keep][:local] = nil
94
+ dont_allow(Dir).[]
95
+ @local.send :cleanup
96
+ end
97
+
98
+ it "should delete extra files" do
99
+ mock(File).unlink("aaaaa1")
100
+ mock(File).unlink("aaaaa2")
101
+ @local.send :cleanup
102
+ end
81
103
  end
82
104
  end
@@ -8,7 +8,6 @@ describe Astrails::Safe::S3 do
8
8
  :bucket => "_bucket",
9
9
  :key => "_key",
10
10
  :secret => "_secret",
11
- :path => "s3_path"
12
11
  },
13
12
  :keep => {
14
13
  :s3 => 2
@@ -40,12 +39,12 @@ describe Astrails::Safe::S3 do
40
39
 
41
40
  @files = [4,1,3,2].to_a.map { |i| stub(o = {}).key {"aaaaa#{i}"}; o }
42
41
 
43
- stub(AWS::S3::Bucket).objects("_bucket", :prefix => "s3_path/_kind-_id", :max_keys => 4) {@files}
42
+ stub(AWS::S3::Bucket).objects("_bucket", :prefix => "_kind/_id/_kind-_id", :max_keys => 4) {@files}
44
43
  stub(AWS::S3::Bucket).find("_bucket").stub![anything].stub!.delete
45
44
  end
46
45
 
47
46
  it "should check [:keep, :s3]" do
48
- mock(@s3.config).[](:keep, :s3) {nil}
47
+ @s3.config[:keep][:s3] = nil
49
48
  dont_allow(@s3.backup).filename
50
49
  @s3.send :cleanup
51
50
  end
@@ -56,21 +55,52 @@ describe Astrails::Safe::S3 do
56
55
  @s3.send :cleanup
57
56
  end
58
57
 
59
- it "should have more tests"
60
-
61
58
  end
62
59
 
63
60
  describe :active do
64
- it "should be true when all params are set"
65
- it "should be false if bucket is missing"
66
- it "should be false if key is missing"
67
- it "should be false if secret is missing"
61
+ before(:each) do
62
+ @s3 = s3
63
+ end
64
+
65
+ it "should be true when all params are set" do
66
+ @s3.should be_active
67
+ end
68
+
69
+ it "should be false if bucket is missing" do
70
+ @s3.config[:s3][:bucket] = nil
71
+ @s3.should_not be_active
72
+ end
73
+
74
+ it "should be false if key is missing" do
75
+ @s3.config[:s3][:key] = nil
76
+ @s3.should_not be_active
77
+ end
78
+
79
+ it "should be false if secret is missing" do
80
+ @s3.config[:s3][:secret] = nil
81
+ @s3.should_not be_active
82
+ end
68
83
  end
69
84
 
70
- describe :prefix do
71
- it "should use s3/path 1st"
72
- it "should use local/path 2nd"
73
- it "should use constant 3rd"
85
+ describe :path do
86
+ before(:each) do
87
+ @s3 = s3
88
+ end
89
+ it "should use s3/path 1st" do
90
+ @s3.config[:s3][:path] = "s3_path"
91
+ @s3.config[:local] = {:path => "local_path"}
92
+ @s3.send(:path).should == "s3_path"
93
+ end
94
+
95
+ it "should use local/path 2nd" do
96
+ @s3.config[:local] = {:path => "local_path"}
97
+ @s3.send(:path).should == "local_path"
98
+ end
99
+
100
+ it "should use constant 3rd" do
101
+ @s3.send(:path).should == "_kind/_id"
102
+ end
103
+
74
104
  end
75
105
 
76
106
  describe :save do
@@ -10,16 +10,16 @@ module Astrails
10
10
  true
11
11
  end
12
12
 
13
- def prefix
14
- @prefix ||= File.expand_path(expand(@config[:local, :path] || raise(RuntimeError, "missing :local/:path")))
13
+ def path
14
+ @path ||= File.expand_path(expand(@config[:local, :path] || raise(RuntimeError, "missing :local/:path")))
15
15
  end
16
16
 
17
17
  def save
18
18
  puts "command: #{@backup.command}" if $_VERBOSE
19
19
 
20
20
  unless $DRY_RUN
21
- FileUtils.mkdir_p(prefix) unless File.directory?(prefix)
22
- system "#{@backup.command}>#{@backup.path = path}"
21
+ FileUtils.mkdir_p(path) unless File.directory?(path)
22
+ system "#{@backup.command}>#{@backup.path = full_path}"
23
23
  end
24
24
 
25
25
  end
@@ -27,11 +27,9 @@ module Astrails
27
27
  def cleanup
28
28
  return unless keep = @config[:keep, :local]
29
29
 
30
- base = File.basename(@backup.filename).split(".").first
30
+ puts "listing files #{base}" if $_VERBOSE
31
31
 
32
- pattern = File.join(prefix, "#{base}*")
33
- puts "listing files #{pattern.inspect}" if $_VERBOSE
34
- files = Dir[pattern] .
32
+ files = Dir["#{base}*"] .
35
33
  select{|f| File.file?(f) && File.size(f) > 0} .
36
34
  sort
37
35
 
@@ -8,8 +8,8 @@ module Astrails
8
8
  bucket && key && secret
9
9
  end
10
10
 
11
- def prefix
12
- @prefix ||= expand(config[:s3, :path] || config[:local, :path] || ":kind/:id")
11
+ def path
12
+ @path ||= expand(config[:s3, :path] || config[:local, :path] || ":kind/:id")
13
13
  end
14
14
 
15
15
  def save
@@ -18,11 +18,11 @@ module Astrails
18
18
  # needed in cleanup even on dry run
19
19
  AWS::S3::Base.establish_connection!(:access_key_id => key, :secret_access_key => secret, :use_ssl => true) unless $LOCAL
20
20
 
21
- puts "Uploading #{bucket}:#{path}" if $_VERBOSE || $DRY_RUN
21
+ puts "Uploading #{bucket}:#{full_path}" if $_VERBOSE || $DRY_RUN
22
22
  unless $DRY_RUN || $LOCAL
23
23
  AWS::S3::Bucket.create(bucket)
24
24
  File.open(@backup.path) do |file|
25
- AWS::S3::S3Object.store(path, file, bucket)
25
+ AWS::S3::S3Object.store(full_path, file, bucket)
26
26
  end
27
27
  puts "...done" if $_VERBOSE
28
28
  end
@@ -33,10 +33,9 @@ module Astrails
33
33
 
34
34
  return unless keep = @config[:keep, :s3]
35
35
 
36
- base = File.basename(@backup.filename).split(".").first
37
36
 
38
- puts "listing files in #{bucket}:#{prefix}/#{base}"
39
- files = AWS::S3::Bucket.objects(bucket, :prefix => "#{prefix}/#{base}", :max_keys => keep * 2)
37
+ puts "listing files in #{bucket}:#{base}" if $_VERBOSE
38
+ files = AWS::S3::Bucket.objects(bucket, :prefix => base, :max_keys => keep * 2)
40
39
  puts files.collect {|x| x.key} if $_VERBOSE
41
40
 
42
41
  files = files.
@@ -11,9 +11,13 @@ module Astrails
11
11
 
12
12
  protected
13
13
 
14
- # prefix is defined in subclass
15
- def path
16
- @path ||= File.join(prefix, @backup.filename) + @backup.extension
14
+ # path is defined in subclass
15
+ def base
16
+ @base ||= File.join(path, File.basename(@backup.filename).split(".").first)
17
+ end
18
+
19
+ def full_path
20
+ @full_path ||= File.join(path, @backup.filename) + @backup.extension
17
21
  end
18
22
 
19
23
  # call block on files to be removed (all except for the LAST 'limit' files
data/templates/script.rb CHANGED
@@ -7,7 +7,7 @@ safe do
7
7
  # :timestamp -> current run timestamp (same for all the backups in the same 'run')
8
8
  # you can set separate :path for all backups (or once globally here)
9
9
  local do
10
- path "/backup/:kind/"
10
+ path "/backup/:kind"
11
11
  end
12
12
 
13
13
  ## uncomment to enable uploads to Amazon S3
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.1.9
4
+ version: 0.1.10
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-05-22 00:00:00 -07:00
13
+ date: 2009-05-27 00:00:00 -07:00
14
14
  default_executable: astrails-safe
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -30,16 +30,16 @@ executables:
30
30
  extensions: []
31
31
 
32
32
  extra_rdoc_files:
33
- - README.markdown
34
33
  - LICENSE
34
+ - README.markdown
35
35
  files:
36
+ - LICENSE
36
37
  - README.markdown
38
+ - Rakefile
37
39
  - VERSION.yml
38
40
  - bin/astrails-safe
39
41
  - examples/example_helper.rb
40
- - examples/integration
41
42
  - examples/integration/archive_integration_example.rb
42
- - examples/unit
43
43
  - examples/unit/archive_example.rb
44
44
  - examples/unit/config_example.rb
45
45
  - examples/unit/gpg_example.rb
@@ -49,11 +49,9 @@ files:
49
49
  - examples/unit/pgdump_example.rb
50
50
  - examples/unit/s3_example.rb
51
51
  - examples/unit/svndump_example.rb
52
- - lib/astrails
53
- - lib/astrails/safe
52
+ - lib/astrails/safe.rb
54
53
  - lib/astrails/safe/archive.rb
55
54
  - lib/astrails/safe/backup.rb
56
- - lib/astrails/safe/config
57
55
  - lib/astrails/safe/config/builder.rb
58
56
  - lib/astrails/safe/config/node.rb
59
57
  - lib/astrails/safe/gpg.rb
@@ -68,17 +66,12 @@ files:
68
66
  - lib/astrails/safe/stream.rb
69
67
  - lib/astrails/safe/svndump.rb
70
68
  - lib/astrails/safe/tmp_file.rb
71
- - lib/astrails/safe.rb
72
- - lib/extensions
73
69
  - lib/extensions/mktmpdir.rb
74
70
  - templates/script.rb
75
- - Rakefile
76
- - LICENSE
77
71
  has_rdoc: true
78
72
  homepage: http://github.com/astrails/safe
79
73
  post_install_message:
80
74
  rdoc_options:
81
- - --inline-source
82
75
  - --charset=UTF-8
83
76
  require_paths:
84
77
  - lib
@@ -101,5 +94,15 @@ rubygems_version: 1.2.0
101
94
  signing_key:
102
95
  specification_version: 2
103
96
  summary: Backup filesystem and databases (MySQL and PostgreSQL) to Amazon S3 (with encryption)
104
- test_files: []
105
-
97
+ test_files:
98
+ - examples/example_helper.rb
99
+ - examples/integration/archive_integration_example.rb
100
+ - examples/unit/archive_example.rb
101
+ - examples/unit/config_example.rb
102
+ - examples/unit/gpg_example.rb
103
+ - examples/unit/gzip_example.rb
104
+ - examples/unit/local_example.rb
105
+ - examples/unit/mysqldump_example.rb
106
+ - examples/unit/pgdump_example.rb
107
+ - examples/unit/s3_example.rb
108
+ - examples/unit/svndump_example.rb