diff options
Diffstat (limited to 'bin/weblogs-rotate')
-rwxr-xr-x | bin/weblogs-rotate | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/bin/weblogs-rotate b/bin/weblogs-rotate index 98e969f..594e0dc 100755 --- a/bin/weblogs-rotate +++ b/bin/weblogs-rotate @@ -15,28 +15,33 @@ ARGV.options do |opts| end -root = '/srv/www/vhosts' +root = '/srv/www/vhosts/' +archive_dir = "/logs-archive/" +logs_dir = "/logs/" + Dir.chdir(root) today = Time.new.strftime("%Y-%m-%d"); 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) + next unless File.exist?( client + logs_dir ) + next unless File.stat( client + logs_dir ).directory? + next unless File.stat( client + archive_dir ).directory? + + root_logs_dir = root+"/"+client+logs_dir + root_archive_dir = root+"/"+client+archive_dir + + Dir.chdir(root_logs_dir) Dir.glob("*.log").each{ |filename| targetname = filename +"."+ today - - if File.exist?(targetname) or - File.exist?(targetname+".gz") or - File.exist?(targetname+".bz2") + if File.exist?(root_archive_dir+targetname) or + File.exist?(root_archive_dir+targetname+".gz") or + File.exist?(root_archive_dir+targetname+".bz2") STDERR.puts("Not moving #{filename}: Target exists."); else puts "Moving #{filename}" if $VERBOSE - File.rename( filename , targetname ); + File.rename( filename , root_archive_dir+targetname ); end } } |