Skip to content

Instantly share code, notes, and snippets.

@rajeshkp
Forked from mlangenberg/deploy.rb
Created September 11, 2013 13:06
Show Gist options
  • Save rajeshkp/6523300 to your computer and use it in GitHub Desktop.
Save rajeshkp/6523300 to your computer and use it in GitHub Desktop.
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