Informatika Mihelac

Articles tagged with capistrano

January 22 2007 capistrano 0 comments

Capistrano can download from remote server

Rails Changeset 6009 includes my patch that adds a “get” helper, to pull a file from a remote server to the localhost. More info about get and example to create backup of production server database is available in previuous posts.

January 15 2007 capistrano 0 comments

Backup remote database with Capistrano

Based on and using capistrano get method posted few days before here comes capistrano recipe to backup database on remote server.

desc <<DESC
Backup remote database from primary server.
DESC
task :remote_backup, :roles => :db, :only => { :primary => true } do
  filename = "dump.#{Time.now.strftime '%Y%m%dT%:%H%M%S'}.sql" 
  on_rollback { delete "/tmp/#{filename}" }
  run "mysqldump -uusername -ppassword database_name > \n
/tmp/#{filename}" do |channel, stream, data|
    puts data
  end
  get "/tmp/#{filename}", "c:/backup/#{filename}" 
  delete "/tmp/#{filename}" 
end
January 11 2007 capistrano 1 comments

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

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