Skip to content

Commit d713941

Browse files
author
fdupoux
committed
Fixed upload of large files to AWS S3 (version 0.2.1)
1 parent d7b2ac5 commit d713941

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

ChangeLog

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
# ChangeLog for rubackup #
33
##############################################################################
44

5-
* 0.2.0
5+
* 0.2.1 (2015-12-01)
6+
- Fixed upload of large files to AWS S3
7+
8+
* 0.2.0 (2015-11-29)
69
- Upgraded to AWS SDK version 2
710

811
* 0.1.1 (2015-03-29):

rubackup.spec

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ rsync -a ${RPM_BUILD_DIR}/rubackup-%{version}/src/ ${RPM_BUILD_ROOT}%{deploydir}
3333

3434
%changelog
3535

36+
* Tue Dec 01 2015 Francois Dupoux - 0.2.1-1
37+
- Fixed upload of large files to AWS S3
38+
3639
* Sun Nov 29 2015 Francois Dupoux - 0.2.0-1
3740
- Upgraded to AWS SDK version 2
3841

src/lib/modules/remote-aws-s3.rb

+10-11
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ def get_s3_access(remote_opts)
4646
keysecret = accesskey.fetch('secret')
4747
# get an instance of the S3 interface.
4848
creds = Aws::Credentials.new(keypublic, keysecret)
49-
s3 = Aws::S3::Client.new(region: awsregion, credentials: creds)
50-
# return s3 object
51-
return s3
49+
s3clt = Aws::S3::Client.new(region: awsregion, credentials: creds)
50+
s3res = Aws::S3::Resource.new(:access_key_id => keypublic, :secret_access_key => keysecret, :region => awsregion)
51+
# return s3 objects
52+
return s3clt,s3res
5253
end
5354

5455
# Return list of file names found in this bucket for this type of backup
@@ -58,8 +59,8 @@ def list(entrydata)
5859
basename = entrydata['bakfile_basename']
5960
bucketdata = remote_opts.fetch('s3_bucket')
6061
bucketname = bucketdata.fetch('bucket')
61-
s3 = get_s3_access(remote_opts)
62-
allobjs = s3.list_objects({bucket: bucketname}).contents # all objects including checksums files
62+
s3clt,s3res = get_s3_access(remote_opts)
63+
allobjs = s3clt.list_objects({bucket: bucketname}).contents # all objects including checksums files
6364
coreobj = allobjs.select { |obj| ((obj.key =~ /#{basename}-(\d{8})/) and (Checksum.checksum?(obj.key) == false)) }
6465
coreobj.each do |obj|
6566
bakfile = Bakfile.new
@@ -82,20 +83,18 @@ def send(entrydata, fullpath)
8283
remote_opts = entrydata.fetch('remote_opts')
8384
bucketdata = remote_opts.fetch('s3_bucket')
8485
bucketname = bucketdata.fetch('bucket')
85-
s3 = get_s3_access(remote_opts)
86+
s3clt,s3res = get_s3_access(remote_opts)
8687
filename = File.basename(fullpath)
87-
File.open(fullpath, 'rb') do |file|
88-
s3.put_object(bucket: bucketname, key: filename, body: file)
89-
end
88+
s3res.bucket(bucketname).object(filename).upload_file(fullpath)
9089
end
9190

9291
# Delete a file in the bucket
9392
def delete(entrydata, filename)
9493
remote_opts = entrydata.fetch('remote_opts')
9594
bucketdata = remote_opts.fetch('s3_bucket')
9695
bucketname = bucketdata.fetch('bucket')
97-
s3 = get_s3_access(remote_opts)
98-
s3.delete_object( { bucket: bucketname, key: filename} )
96+
s3clt,s3res = get_s3_access(remote_opts)
97+
s3clt.delete_object( { bucket: bucketname, key: filename} )
9998
end
10099

101100
end

src/rubackup.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
require 'yaml'
2727

2828
# Define constants
29-
$RUBACKUP_VERSION = "0.2.0"
29+
$RUBACKUP_VERSION = "0.2.1"
3030
$RUBACKUP_MIN_RUBY = 1.9 # Required by Open3.pipeline()
3131

3232
# Define global variables

0 commit comments

Comments
 (0)