Created
June 25, 2012 13:27
-
-
Save mlangenberg/2988578 to your computer and use it in GitHub Desktop.
Capistrano task to download all application log files (including logrotated)
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
namespace :log do | |
desc "Downloads application logs to ./log/deploy/<RAILS_ENV>/<TIMESTAMP>/" | |
task :fetch, :roles => :app do | |
source = "#{shared_path}/log/#{rails_env}.log*" | |
files_per_host = {} | |
run "ls #{source}" do |channel, stream, data| | |
files_per_host[channel[:host]] = data.split("\n") | |
end | |
destination = File.join('log', 'deploy') | |
target_dir = File.join(destination, rails_env, Time.now.strftime("%Y%m%d_%H%M")) | |
FileUtils.mkdir_p(target_dir) | |
files_per_host.each do |host, files| | |
files.each do |file| | |
file_name = file.split("/").last | |
download file, "#{target_dir}/$CAPISTRANO:HOST$-#{file_name}", :via => :scp, :hosts => host | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment