Skip to content

Instantly share code, notes, and snippets.

@silasb
Forked from mlangenberg/deploy.rb
Last active December 14, 2015 14:39
Show Gist options
  • Save silasb/5102484 to your computer and use it in GitHub Desktop.
Save silasb/5102484 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[:xserver]] = data.split("\n").map(&:split)
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}/#{file_name}", :via => :scp
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment