Created
June 6, 2011 15:50
-
-
Save ckdake/1010507 to your computer and use it in GitHub Desktop.
rake task to show size of all files in a s3 account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fog' | |
desc "Tell us how much space is in use on S3" | |
namespace :s3 do | |
task usage: :environment do | |
size = 0 | |
connection = Fog::Storage.new( | |
provider: 'AWS', | |
aws_access_key_id: ENV['aws_access_key_id'], | |
aws_secret_access_key: ENV['aws_secret_access_key'], | |
region: 'us-east-1' | |
) | |
connection.directories.each do |directory| | |
directory.files.each do |file| | |
size += file.content_length | |
end | |
end | |
puts "#{size / 1073741824} GB" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment