lib/astrails/safe/s3.rb in astrails-safe-0.2.7 vs lib/astrails/safe/s3.rb in astrails-safe-0.3.0
- old
+ new
@@ -12,10 +12,11 @@
def path
@path ||= expand(config[:s3, :path] || config[:local, :path] || ":kind/:id")
end
def save
+ # FIXME: user friendly error here :)
raise RuntimeError, "pipe-streaming not supported for S3." unless @backup.path
# needed in cleanup even on dry run
AWS::S3::Base.establish_connection!(:access_key_id => key, :secret_access_key => secret, :use_ssl => true) unless $LOCAL
@@ -24,11 +25,11 @@
if File.stat(@backup.path).size > MAX_S3_FILE_SIZE
STDERR.puts "ERROR: File size exceeds maximum allowed for upload to S3 (#{MAX_S3_FILE_SIZE}): #{@backup.path}"
return
end
benchmark = Benchmark.realtime do
- AWS::S3::Bucket.create(bucket)
+ AWS::S3::Bucket.create(bucket) unless bucket_exists?(bucket)
File.open(@backup.path) do |file|
AWS::S3::S3Object.store(full_path, file, bucket)
end
end
puts "...done" if $_VERBOSE
@@ -49,11 +50,11 @@
collect {|x| x.key}.
sort
cleanup_with_limit(files, keep) do |f|
puts "removing s3 file #{bucket}:#{f}" if $DRY_RUN || $_VERBOSE
- AWS::S3::Bucket.find(bucket)[f].delete unless $DRY_RUN || $LOCAL
+ AWS::S3::Bucket.objects(bucket, :prefix => f)[0].delete unless $DRY_RUN || $LOCAL
end
end
def bucket
@config[:s3, :bucket]
@@ -65,8 +66,15 @@
def secret
@config[:s3, :secret]
end
+ private
+
+ def bucket_exists?(bucket)
+ true if AWS::S3::Bucket.find(bucket)
+ rescue AWS::S3::NoSuchBucket
+ false
+ end
end
end
end