Permalink
Browse files

[#4470] Documentation for pruning reports

Also improved the error feedback for when 'rake reports:prune' is run.
  • Loading branch information...
1 parent 94432c6 commit 55d4ece4f0b50111ce42eb3f39063e4b1955c729 Matt Robinson committed Aug 11, 2010
Showing with 30 additions and 15 deletions.
  1. +18 −0 README.markdown
  2. +12 −15 lib/tasks/prune_reports.rake
View
@@ -277,6 +277,23 @@ To restore the Puppet Dashboard from a file called `production.sql` to your `pro
rake RAILS_ENV=production FILE=production.sql db:raw:restore
+Database cleanup
+----------------
+
+Reports will build up over time which you may want to delete because of space
+or data rentention policy issues. A rake task is included to help with this,
+and as with the other rake tasks it should be run from the same directory
+this README.markdown file is in.
+
+### Prune
+
+To delete reports older than 1 month:
+
+ rake RAILS_ENV=production reports:prune upto=1 unit=mon
+
+If you run 'rake reports:prune' without any arguments or incorrect arguments it
+will print the available units.
+
Contributors
------------
@@ -286,3 +303,4 @@ Contributors
* Andrew Maier <andrew.maier@gatech.edu>
* Scott Smith <scott@ohlol.net>
* Ian Ward Comfort <icomfort@stanford.edu>
+* Matt Robinson <matt@puppetlabs.com>
@@ -1,20 +1,6 @@
namespace :reports do
desc 'prune old reports from the databases'
task :prune => :environment do
- if ENV['upto'] =~ /^\d+/
- upto = ENV['upto']
- else
- puts 'You must specify how far up you want to prune (as an integer).'
- exit 1
- end
-
- if ENV['unit']
- unit = ENV['unit']
- else
- puts 'You must specify the unit of time. (min,hr,day,wk,mon,yr)'
- exit 1
- end
-
units = {
'min' => '60',
'hr' => '3600',
@@ -23,11 +9,22 @@ namespace :reports do
'mon' => '2592000',
'yr' => '31536000'
}
+ known_units = units.keys.join(',')
+
+ unless ENV['upto'] =~ /^\d+/ && ENV['unit']
+ puts "You must specify how far up you want to prune. upto={some integer}"
+ puts "You must specify the unit of time. unit={#{known_units}}"
+ puts "Example: 'rake reports:prune upto=1 unit=month'"
+ exit 1
+ end
+
+ upto = ENV['upto']
+ unit = ENV['unit']
if units.has_key?(unit)
esec = Time.now.gmtime - upto.to_i * units[unit].to_i
else
- puts 'I don\'t know that unit.'
+ puts "I don't know that unit. Known units are #{known_units}"
exit 1
end

0 comments on commit 55d4ece

Please sign in to comment.