Skip to content

Instantly share code, notes, and snippets.

@dcarley
Last active December 15, 2015 05:59
Show Gist options
  • Save dcarley/5212980 to your computer and use it in GitHub Desktop.
Save dcarley/5212980 to your computer and use it in GitHub Desktop.
#!/bin/env ruby
require 'fileutils'
require 'pathname'
ARGV.each do |old_name|
match = old_name.match(/^(.+)\/([^\/]+_production)\/(.*?)_?(nginx|varnish)\/(.+\.wsp)$/)
next unless match
root, host, vhost, prog, wsp = match.captures
vhost.gsub!(/\//, '_')
new_name = File.join(root, host, "#{prog}_logs", vhost, wsp)
dir_name = File.dirname(new_name)
new_relative = Pathname.new(new_name).relative_path_from(Pathname.new(old_name).parent)
unless File.exist?(new_name)
puts new_name
FileUtils.mkdir_p(dir_name)
FileUtils.mv(old_name, new_name)
FileUtils.ln_s(new_relative, old_name)
end
end
time sudo find /opt/graphite/storage/whisper/*_production \
\( -name http_???\.wsp -or -name time_request\.wsp -or -name time_upstream\.wsp \) \
-type f -mmin -30 \
-exec ruby ~/rename_wsp.rb {} \+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment