Jan 10

Capistrano get method - download files from server

Still looking if there is better way to do this (and I bet there it is :), but until I realize, add to top of deploy.rb:

# Get file remote_path from FIRST server targetted by
# the current task and transfer it to local machine as path, SFTP required
def actor.get(remote_path, path, options = {})
    execute_on_servers(options) do |servers|
      self.sessions[servers.first].sftp.connect do |tsftp|
        logger.info "Get #{remote_path} to #{path}" 
        tsftp.get_file remote_path, path
      end
    end
end
Sample recipe to get production log from server:

task :download_log, :roles => :web, :only => { :primary => true } do
get "#{deploy_to}/current/log/production.log",
     "log/production.log.web" //download server log
end