Informatika Mihelac
January 11 2007 capistrano | code | rails

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
comments feed

2 comments

  1. # On September 01, 2007 at 01:09 AM, Tom said:

    This is sweet. I use this for production logs and my database backup files

  2. # On July 30, 2008 at 18:07 PM, todd A. Fisher said:

    newer versions of cap have download, seems to work the same way…

    1. Initiates a download from remote to local, asynchronously. This
    2. method will return a new Net::SFTP::Operations::Download instance, and requires
    3. that the event loop be run in order for the download to progress. See
    4. Net::SFTP::Operations::Download for a full discussion of hos this method can be
    5. used. #
    6. download = sftp.download(”/remote/path”, ”/local/path”)
    7. download.wait def download(remote, local, options={}, &block) Operations::Download.new(self, local, remote, options, &block) end

Speak your mind:

(Required)

(Required)


(You may use textile in your comments.)

About

I am Bojan Mihelac and this blog is dedicated to share code, thoughts, tools and advices I came up with while working in Informatika Mihelac.

Contact: bmihelac@mihelac.org

RSS feedSubscribe to RSS Feed