Class: S3snapshot::DirUpload
- Defined in:
- lib/s3snapshot/dir_upload.rb
Constant Summary
Constants inherited from SyncOp
SyncOp::COMPLETE_EXTENSION, SyncOp::COMPLETE_FILE, SyncOp::COMPLETE_MARKER
Instance Method Summary collapse
-
#initialize(aws_id, aws_key, bucket_name, prefix, local_dir) ⇒ DirUpload
constructor
A new instance of DirUpload.
- #upload ⇒ Object
Methods inherited from SyncOp
#aws, #bucket, #complete_path, #complete_prefix, #timepath
Constructor Details
#initialize(aws_id, aws_key, bucket_name, prefix, local_dir) ⇒ DirUpload
Returns a new instance of DirUpload.
15 16 17 18 19 20 |
# File 'lib/s3snapshot/dir_upload.rb', line 15 def initialize(aws_id, aws_key, bucket_name, prefix, local_dir ) super(aws_id, aws_key, bucket_name) @local_dir = local_dir @prefix = prefix end |
Instance Method Details
#upload ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/s3snapshot/dir_upload.rb', line 22 def upload start_time = TimeFactory.utc_time prefix_path = timepath(@prefix, start_time) files = get_local_files files.each do |file| file_name = file[@local_dir.length..-1]; #Strip the leading "/" from file paths if file_name.length > 0 && file_name[0] == '/' file_name = file[1..-1] end path = "#{prefix_path}/#{file_name}" puts "uploading '#{file}' to '#{@bucket_name}/#{path}'" File.open(file) do |file| bucket.files.create(:key =>path, :body => file) end end puts "Writing complete marker" #Upload the complete marker bucket.files.create(:key => complete_path(@prefix, start_time), :body => TimeFactory.utc_time.iso8601) puts "backup complete!" end |