diff options
Diffstat (limited to 'bin/weblogs-compress')
-rwxr-xr-x | bin/weblogs-compress | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/bin/weblogs-compress b/bin/weblogs-compress new file mode 100755 index 0000000..f731e47 --- /dev/null +++ b/bin/weblogs-compress @@ -0,0 +1,41 @@ +#!/usr/bin/ruby + +require 'optparse' + +$VERBOSE = nil + +def show_help(parser, code=0, io=STDOUT) + io.puts parser + exit(code) +end +ARGV.options do |opts| + opts.on_tail("-h", "--help", "Display this help screen") { show_help(opts) } + opts.on("-v", "--verbose" , nil, "Be verbose") { $VERBOSE = 1 } + opts.parse! +end + + +root = '/srv/www/vhosts' +Dir.chdir(root) + +Dir.glob("*").each{ |client| + Dir.chdir(root) + next unless File.stat( client ).directory? + next unless File.exist?( client + "/logs" ) + next unless File.stat( client + "/logs" ).directory? + + logroot = root+"/"+client+"/logs" + Dir.chdir(logroot) + Dir.glob("*.log.*").each{ |filename| + match = /^(.*)\.log\.[0-9]{4,4}-[0-9][0-9]-[0-9][0-9]$/.match(filename) + next unless match + + if File.exist?(filename+".gz") or + File.exist?(filename+".bz2") + STDERR.puts("Not compressing #{filename}: Target exists."); + else + puts "Compressing #{filename}" if $VERBOSE + system("gzip -9 #{filename}") or throw("system(gzip -9 #{filename}) failed.") + end + } +} |