Skip to content

Instantly share code, notes, and snippets.

@ckdake
Created June 6, 2011 15:50
Show Gist options
  • Save ckdake/1010507 to your computer and use it in GitHub Desktop.
Save ckdake/1010507 to your computer and use it in GitHub Desktop.
rake task to show size of all files in a s3 account
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