Class: S3
- Inherits:
-
Rehabilitate::Plugin
- Object
- Rehabilitate::Plugin
- S3
- Defined in:
- lib/rehabilitate/plugins/s3.rb
Instance Method Summary collapse
Methods inherited from Rehabilitate::Plugin
Instance Method Details
#download(options) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rehabilitate/plugins/s3.rb', line 42 def download() log "S3 downloading backup" log "Number #{.number}" location = parse_upload_string(.location) s3 = setup_fog(location) local_file = "" dir = s3.directories.get(location[:bucket]) backups = sorted_backups(dir.files) if backups[.number] log "Restoring #{backups[.number]}" restore_key = backups[.number] output = %x{ s3cmd --config /etc/s3cfg get --recursive --skip-existing s3://#{location[:bucket]}/#{backups[.number]} #{.tmp}} output.split("\n").each {|f| log f} else log "Invalid number specified, use --list first to get the id you want to restore" end backup_files = Dir.glob("#{.tmp}/#{backups[.number].split("/").last}/*") log "Joining #{backup_files.size} files..." joiner = Splitter.new joined = backup_files.size > 1 ? joiner.join(backup_files) : backup_files ._tmp_files << joined ._backup_files = joined.is_a?(Array) ? joined : [joined] end |
#list(options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rehabilitate/plugins/s3.rb', line 7 def list() location = parse_upload_string(.location) s3 = setup_fog(location) log "Listing bucket contents for #{location[:bucket]}" dir = s3.directories.get(location[:bucket]) backups = sorted_backups(dir.files) backups.each_with_index do |backup, i| say "#{i}: #{prettify(backup)}" end end |
#upload(options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rehabilitate/plugins/s3.rb', line 19 def upload() location = parse_upload_string(.location) s3 = setup_fog(location) location[:dir] = "#{location[:dir]}/#{._base_backup_name}" log "Creating bucket #{location[:bucket]} if it doesn't exist" s3.directories.create(:key => location[:bucket]) ._backup_files.collect! do |local_file| if File.size(local_file) > .split_size splitter = Splitter.new local_file = splitter.split(local_file, ) else [local_file] end local_file.each do |local_file| log "Uploading #{local_file}" log " => #{local_file}" log %{ s3cmd --config /etc/s3cfg #{.} put #{local_file} s3://#{location[:bucket]}/#{location[:dir]}/ } log %x{ s3cmd --config /etc/s3cfg #{.} put #{local_file} s3://#{location[:bucket]}/#{location[:dir]}/ } end end end |