astrails-safe 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -136,6 +136,7 @@ Example configuration
136
136
  sftp do
137
137
  host "sftp.astrails.com"
138
138
  user "astrails"
139
+ # port 8023
139
140
  password "ssh password for sftp"
140
141
  end
141
142
 
@@ -186,6 +187,7 @@ Example configuration
186
187
  end
187
188
 
188
189
  tar do
190
+ options "-h" # dereference symlinks
189
191
  archive "git-repositories", :files => "/home/git/repositories"
190
192
  archive "dot-configs", :files => "/home/*/.[^.]*"
191
193
  archive "etc", :files => "/etc", :exclude => "/etc/puppet/other"
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 2
4
- :patch: 5
4
+ :patch: 6
@@ -15,14 +15,14 @@ describe Astrails::Safe::S3 do
15
15
  }
16
16
  end
17
17
 
18
- def def_backup
18
+ def def_backup(extra = {})
19
19
  {
20
20
  :kind => "_kind",
21
21
  :filename => "/backup/somewhere/_kind-_id.NOW.bar",
22
22
  :extension => ".bar",
23
23
  :id => "_id",
24
24
  :timestamp => "NOW"
25
- }
25
+ }.merge(extra)
26
26
  end
27
27
 
28
28
  def s3(config = def_config, backup = def_backup)
@@ -104,9 +104,57 @@ describe Astrails::Safe::S3 do
104
104
  end
105
105
 
106
106
  describe :save do
107
- it "should establish s3 connection"
108
- it "should RuntimeError if no local file (i.e. :local didn't run)"
109
- it "should open local file"
110
- it "should upload file"
107
+ def add_stubs(*stubs)
108
+ stubs.each do |s|
109
+ case s
110
+ when :connection
111
+ stub(AWS::S3::Base).establish_connection!(:access_key_id => "_key", :secret_access_key => "_secret", :use_ssl => true)
112
+ when :stat
113
+ stub(File).stat("foo").stub!.size {123}
114
+ when :create_bucket
115
+ stub(AWS::S3::Bucket).create
116
+ when :file_open
117
+ stub(File).open("foo") {|f, block| block.call(:opened_file)}
118
+ when :s3_store
119
+ stub(AWS::S3::S3Object).store(@full_path, :opened_file, "_bucket")
120
+ end
121
+ end
122
+ end
123
+
124
+ before(:each) do
125
+ @s3 = s3(def_config, def_backup(:path => "foo"))
126
+ @full_path = "_kind/_id/backup/somewhere/_kind-_id.NOW.bar.bar"
127
+ end
128
+
129
+ it "should fail if no backup.file is set" do
130
+ @s3.backup.path = nil
131
+ proc {@s3.send(:save)}.should raise_error(RuntimeError)
132
+ end
133
+
134
+ it "should establish s3 connection" do
135
+ mock(AWS::S3::Base).establish_connection!(:access_key_id => "_key", :secret_access_key => "_secret", :use_ssl => true)
136
+ add_stubs(:stat, :create_bucket, :file_open, :s3_store)
137
+ @s3.send(:save)
138
+ end
139
+
140
+ it "should open local file" do
141
+ add_stubs(:connection, :stat, :create_bucket)
142
+ mock(File).open("foo")
143
+ @s3.send(:save)
144
+ end
145
+
146
+ it "should upload file" do
147
+ add_stubs(:connection, :stat, :create_bucket, :file_open)
148
+ mock(AWS::S3::S3Object).store(@full_path, :opened_file, "_bucket")
149
+ @s3.send(:save)
150
+ end
151
+
152
+ it "should fail on files bigger then 5G" do
153
+ add_stubs(:connection)
154
+ mock(File).stat("foo").stub!.size {5*1024*1024*1024+1}
155
+ mock(STDERR).puts(anything)
156
+ dont_allow(Benchmark).realtime
157
+ @s3.send(:save)
158
+ end
111
159
  end
112
160
  end
@@ -1,6 +1,7 @@
1
1
  module Astrails
2
2
  module Safe
3
3
  class S3 < Sink
4
+ MAX_S3_FILE_SIZE = 5368709120
4
5
 
5
6
  protected
6
7
 
@@ -20,6 +21,10 @@ module Astrails
20
21
 
21
22
  puts "Uploading #{bucket}:#{full_path}" if $_VERBOSE || $DRY_RUN
22
23
  unless $DRY_RUN || $LOCAL
24
+ if File.stat(@backup.path).size > MAX_S3_FILE_SIZE
25
+ STDERR.puts "ERROR: File size exceeds maximum allowed for upload to S3 (#{MAX_S3_FILE_SIZE}): #{@backup.path}"
26
+ return
27
+ end
23
28
  benchmark = Benchmark.realtime do
24
29
  AWS::S3::Bucket.create(bucket)
25
30
  File.open(@backup.path) do |file|
@@ -20,6 +20,7 @@ module Astrails
20
20
  unless $DRY_RUN || $LOCAL
21
21
  opts = {}
22
22
  opts[:password] = password if password
23
+ opts[:port] = port if port
23
24
  Net::SFTP.start(host, user, opts) do |sftp|
24
25
  puts "Sending #{@backup.path} to #{full_path}" if $_VERBOSE
25
26
  begin
@@ -46,7 +47,10 @@ module Astrails
46
47
  return unless keep = @config[:keep, :sftp]
47
48
 
48
49
  puts "listing files: #{host}:#{base}*" if $_VERBOSE
49
- Net::SFTP.start(host, user, :password => password) do |sftp|
50
+ opts = {}
51
+ opts[:password] = password if password
52
+ opts[:port] = port if port
53
+ Net::SFTP.start(host, user, opts) do |sftp|
50
54
  files = sftp.dir.glob(path, File.basename("#{base}*"))
51
55
 
52
56
  puts files.collect {|x| x.name } if $_VERBOSE
@@ -74,6 +78,11 @@ module Astrails
74
78
  def password
75
79
  @config[:sftp, :password]
76
80
  end
81
+
82
+ def port
83
+ @config[:sftp, :port]
84
+ end
85
+
77
86
  end
78
87
  end
79
88
  end
@@ -28,6 +28,7 @@ safe do
28
28
  # sftp do
29
29
  # host "YOUR_REMOTE_HOSTNAME"
30
30
  # user "YOUR_REMOTE_USERNAME"
31
+ # # port "NON STANDARD SSH PORT"
31
32
  # password "YOUR_REMOTE_PASSWORD"
32
33
  # path ":kind/:id" # this is the default
33
34
  # end
@@ -87,7 +88,7 @@ safe do
87
88
  # # uncomment to enable
88
89
  # # backup PostgreSQL databases with pg_dump
89
90
  # pgdump do
90
- # option "-i -x -O"
91
+ # options "-i -x -O"
91
92
  #
92
93
  # user "markmansour"
93
94
  # # password "" - leave this out if you have ident setup
@@ -99,6 +100,8 @@ safe do
99
100
  # end
100
101
 
101
102
  tar do
103
+ # options "-h" # uncomment this to dereference symbolic links
104
+
102
105
  # 'archive' is a collection item, just like 'database'
103
106
  # archive "git-repositories" do
104
107
  # # files and directories to backup
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.5
4
+ version: 0.2.6
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-20 00:00:00 +02:00
13
+ date: 2009-12-21 00:00:00 +02:00
14
14
  default_executable: astrails-safe
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency