sweety_backy 0.0.17 → 0.0.19

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/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  *.gem
3
3
  .bundle
4
4
  pkg/*
5
+ tmp
@@ -27,39 +27,49 @@ module SweetyBacky
27
27
  end
28
28
 
29
29
  def self.clean_files( opts )
30
- SweetyBacky::Utils.log "cleaning files on #{opts[:working_path]}/files/"
30
+ SweetyBacky::Utils.log "cleaning files on #{opts[:target_path]}/files/"
31
31
 
32
32
  opts[:paths].each do |path|
33
33
  SweetyBacky::Utils.log "cleaning file #{path}"
34
34
 
35
35
  [:yearly, :monthly, :weekly, :daily].each do |period|
36
36
  paths_in(
37
- "#{opts[:working_path]}/files/#{SweetyBacky::Utils.namerize( path )}.*.#{period.to_s}.tar.gz",
37
+ "#{opts[:target_path]}/files/#{SweetyBacky::Utils.namerize( path )}.*.#{period.to_s}.tar.gz",
38
38
  opts
39
39
  ).sort[0..(-1*(opts[period]+1))].each do |file_path|
40
40
  remove_path( file_path, opts )
41
+ remove_path( "#{file_path}.md5", opts ) if exists?( "#{file_path}.md5", opts )
41
42
  end
42
43
  end
43
44
  end
44
45
  end
45
46
 
46
47
  def self.clean_databases( opts )
47
- SweetyBacky::Utils.log "cleaning databases on #{opts[:working_path]}/databases/"
48
+ SweetyBacky::Utils.log "cleaning databases on #{opts[:target_path]}/databases/"
48
49
 
49
50
  opts[:databases].each do |database_name|
50
51
  SweetyBacky::Utils.log "cleaning database #{database_name}"
51
52
 
52
53
  [:yearly, :monthly, :weekly, :daily].each do |period|
53
54
  paths_in(
54
- "#{opts[:working_path]}/databases/#{database_name}.*.#{period.to_s}.sql.tar.gz",
55
+ "#{opts[:target_path]}/databases/#{database_name}.*.#{period.to_s}.sql.tar.gz",
55
56
  opts
56
57
  ).sort[0..(-1*(opts[period]+1))].each do |file_path|
57
58
  remove_path( file_path, opts )
59
+ remove_path( "#{file_path}.md5", opts ) if exists?( "#{file_path}.md5", opts )
58
60
  end
59
61
  end
60
62
  end
61
63
  end
62
64
 
65
+ def self.exists?( path, opts )
66
+ if( opts[:storage_system].to_sym == :s3 )
67
+ return SweetyBacky::S3.exists?( path, opts[:s3_opts] )
68
+ else
69
+ return File.exists?( path )
70
+ end
71
+ end
72
+
63
73
  def self.paths_in( path, opts )
64
74
  if( opts[:storage_system].to_sym == :s3 )
65
75
  return SweetyBacky::S3.paths_in( path, opts[:s3_opts] )
@@ -29,8 +29,10 @@ module SweetyBacky
29
29
 
30
30
  if( @opts[:storage_system].to_sym == :s3 )
31
31
  @opts[:working_path] = File.join( Dir::tmpdir, "sweety_backy_#{Time.now.to_i}" )
32
+ @opts[:target_path] = @opts[:s3_opts][:path]
32
33
  else
33
34
  @opts[:working_path] = @opts[:local_opts][:path]
35
+ @opts[:target_path] = @opts[:local_opts][:path]
34
36
  end
35
37
  end
36
38
 
@@ -126,13 +128,13 @@ module SweetyBacky
126
128
  def upload_databases_backup_to_s3( backup_path, md5_path )
127
129
  SweetyBacky::S3.upload(
128
130
  backup_path,
129
- "#{@opts[:s3_opts][:path]}/databases/#{File.basename( backup_path )}",
131
+ "#{@opts[:target_path]}/databases/#{File.basename( backup_path )}",
130
132
  @opts[:s3_opts]
131
133
  )
132
134
 
133
135
  SweetyBacky::S3.upload(
134
136
  md5_path,
135
- "#{@opts[:s3_opts][:path]}/databases/#{File.basename( md5_path )}",
137
+ "#{@opts[:target_path]}/databases/#{File.basename( md5_path )}",
136
138
  @opts[:s3_opts]
137
139
  )
138
140
 
@@ -143,13 +145,13 @@ module SweetyBacky
143
145
  def upload_files_backup_to_s3( backup_path, md5_path )
144
146
  SweetyBacky::S3.upload(
145
147
  backup_path,
146
- "#{@opts[:s3_opts][:path]}/files/#{File.basename( backup_path )}",
148
+ "#{@opts[:target_path]}/files/#{File.basename( backup_path )}",
147
149
  @opts[:s3_opts]
148
150
  )
149
151
 
150
152
  SweetyBacky::S3.upload(
151
153
  md5_path,
152
- "#{@opts[:s3_opts][:path]}/files/#{File.basename( md5_path )}",
154
+ "#{@opts[:target_path]}/files/#{File.basename( md5_path )}",
153
155
  @opts[:s3_opts]
154
156
  )
155
157
 
@@ -22,15 +22,19 @@ module SweetyBacky
22
22
  object
23
23
  end
24
24
 
25
+ def self.exists?( path, opts )
26
+ return object( path, opts ).exists?
27
+ end
28
+
25
29
  def self.paths_in( path, opts )
26
30
  s3 = AWS::S3.new( read_s3_password( opts[:passwd_file] ) )
27
31
  bucket = s3.buckets[ opts[:bucket] ]
28
32
 
29
33
  regex = Regexp.escape( path ).gsub('\*', '.*').gsub('\?', '.')
30
-
31
- objects = bucket.objects.select { |e| e.key =~ /#{regex}/ }
32
- paths = objects.map(&:key)
33
-
34
+
35
+ objects = bucket.objects.select { |e| e.key =~ /^#{regex}$/ }
36
+ paths = objects.map(&:key)
37
+
34
38
  return paths
35
39
  end
36
40
 
@@ -1,3 +1,3 @@
1
1
  module SweetyBacky
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.19"
3
3
  end
@@ -56,7 +56,8 @@ class CommanderTest < Test::Unit::TestCase
56
56
  :local_opts => {
57
57
  :path => @tmp_dir
58
58
  },
59
- :working_path => @tmp_dir
59
+ :working_path => @tmp_dir,
60
+ :target_path => @tmp_dir
60
61
  }
61
62
 
62
63
  Dir.mkdir( "#{@tmp_dir}/files" ) unless File.exists?( "#{@tmp_dir}/files" )
@@ -92,7 +93,7 @@ class CommanderTest < Test::Unit::TestCase
92
93
 
93
94
  SweetyBacky::Commander.clean( opts )
94
95
 
95
- files_keeped = Dir.glob( "#{@tmp_dir}/files/*" ).join( "\n" )
96
+ files_keeped = Dir.glob( "#{@tmp_dir}/files/*" ).join( "\n" )
96
97
  databases_keeped = Dir.glob( "#{@tmp_dir}/databases/*" ).join( "\n" )
97
98
 
98
99
  # files to keep
@@ -100,6 +100,8 @@ class RunnerTest < Test::Unit::TestCase
100
100
  assert_equal( 4, runner.opts[:daily] )
101
101
  assert_equal( :local, runner.opts[:storage_system] )
102
102
  assert_equal( '/local/path', runner.opts[:local_opts][:path] )
103
+ assert_equal( '/local/path', runner.opts[:working_path] )
104
+ assert_equal( '/local/path', runner.opts[:target_path] )
103
105
  end
104
106
 
105
107
  end
@@ -18,7 +18,8 @@ class CommanderS3Test < Test::Unit::TestCase
18
18
  :path => 'test/path',
19
19
  :passwd_file => '~/.s3.passwd'
20
20
  },
21
- :working_path => @tmp_dir
21
+ :working_path => @tmp_dir,
22
+ :target_path => 'test/path'
22
23
  }
23
24
 
24
25
  s3 = AWS::S3.new( SweetyBacky::S3.read_s3_password( @opts[:s3_opts][:passwd_file] ) )
@@ -67,6 +67,30 @@ class RunnerS3Test < Test::Unit::TestCase
67
67
  ].exists?
68
68
  )
69
69
  end
70
+
71
+ def test_initialize_with_config_file
72
+ SweetyBacky::OptsReader.expects( :read_opts ).with( '/path/config.yml' ).returns(
73
+ {
74
+ :paths => [ 'pepe', 'juan' ],
75
+ :storage_system => :s3,
76
+ :s3_opts => {
77
+ :path => '/s3/path'
78
+ }
79
+ }
80
+ )
81
+
82
+ runner = SweetyBacky::Runner.new( "/path/config.yml" )
83
+
84
+ assert_equal( [ "pepe", "juan" ], runner.opts[:paths] )
85
+ assert_equal( [], runner.opts[:databases] )
86
+ assert_equal( 1, runner.opts[:yearly] )
87
+ assert_equal( 1, runner.opts[:monthly] )
88
+ assert_equal( 2, runner.opts[:weekly] )
89
+ assert_equal( 4, runner.opts[:daily] )
90
+ assert_equal( :s3, runner.opts[:storage_system] )
91
+ assert_equal( '/s3/path', runner.opts[:s3_opts][:path] )
92
+ assert_equal( '/s3/path', runner.opts[:target_path] )
93
+ end
70
94
 
71
95
  end
72
96
 
@@ -57,4 +57,10 @@ class S3Test < Test::Unit::TestCase
57
57
  assert( !@bucket.objects[ "test/path/file2.txt" ].exists? )
58
58
  end
59
59
 
60
+ def test_exists
61
+ SweetyBacky::S3.upload( "#{FIXTURES_PATH}/file.txt", "test/path/file1.txt", @opts )
62
+ assert_equal( true, SweetyBacky::S3.exists?( "test/path/file1.txt", @opts ) )
63
+ assert_equal( false, SweetyBacky::S3.exists?( "test/path/file2.txt", @opts ) )
64
+ end
65
+
60
66
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sweety_backy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 61
4
+ hash: 57
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 17
10
- version: 0.0.17
9
+ - 19
10
+ version: 0.0.19
11
11
  platform: ruby
12
12
  authors:
13
13
  - Fernando Guillen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-23 00:00:00 +02:00
18
+ date: 2011-10-04 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency