Created
January 30, 2014 11:40
-
-
Save daveadams/8706838 to your computer and use it in GitHub Desktop.
Sakai site disk usage report using sakai-info gem
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
#!/usr/bin/env ruby | |
# | |
# disk-report.rb | |
# Reports disk usage broken down by category for all sites in a Sakai instance. | |
# | |
# Written by David Adams ([email protected]) | |
# | |
# This software is licensed to the Public Domain; No Rights Reserved | |
# | |
# Requirements | |
# You must install the sakai-info gem as well as a database driver. | |
# Tested drivers are: | |
# For Oracle: ruby-oci8 | |
# For MySQL: mysql2 | |
# | |
# MySQL access may also work with the mysqlplus or mysql drivers. | |
# | |
###################################################################### | |
# | |
# Variables | |
# | |
# CONNECTION_STRING | |
# | |
# connect to database using Sequel connection strings | |
# (see also http://sequel.jeremyevans.net/rdoc/files/doc/opening_databases_rdoc.html) | |
# | |
# Oracle (requires 'ruby-oci8' gem to be installed) | |
# "oracle://username:password@dbid" | |
# | |
# MySQL using 'mysql2' gem | |
# "mysql2://username:password@dbhostname/dbname" | |
# | |
# MySQL using the 'mysqlplus' or 'mysql' gems | |
# "mysql://username:password@dbhostname/dbname" | |
# | |
CONNECTION_STRING = "oracle://username:password@dbsid" | |
# | |
###################################################################### | |
require 'sakai-info' | |
SakaiInfo::DB.configure({ "db" => CONNECTION_STRING }) | |
puts "site_id,site_type,resources,attachments,melete,dropbox,total" | |
# write report | |
SakaiInfo::Site.find_all_ids.each do |site_id| | |
site = SakaiInfo::Site.find(site_id) | |
report_fields = [site.id, | |
site.type, | |
site.resource_storage.size_on_disk, | |
site.attachment_storage.size_on_disk, | |
site.melete_storage.size_on_disk, | |
site.dropbox_storage.size_on_disk, | |
site.total_disk_usage | |
] | |
puts(report_fields.join(",")) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment