Skip to content

Instantly share code, notes, and snippets.

@blasterpal
Last active December 10, 2015 21:38
Show Gist options
  • Select an option

  • Save blasterpal/4496287 to your computer and use it in GitHub Desktop.

Select an option

Save blasterpal/4496287 to your computer and use it in GitHub Desktop.
Use fog to grab a file from S3 and save locally on server. Useful for transferring large backups from server to server where network prevents direct communication.
require 'fog'
# Fetch and save backup on TARGET
storage = Fog::Storage.new({:provider => 'AWS', :aws_access_key_id => ENV['AWS_KEY'], :aws_secret_access_key => ENV['AWS_SECRET']})
dir = storage.directories.get('<YOUR DIR>')
file = dir.files.get "<S3 PATH TO FILE>"
output = File.new "<LOCAL FILE PATH>", "w"
output.write file.body
output.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment