What a cool hack!

I spent some time trying to extend capistrano to include a get_file
function. I ran into trouble with the non-blocking loop in transfer()
and have put it off till later.

I ended up writing an ugly but useful task that copies the contents of
the production database to the development database. So developers
can run 'cap dbpull' to get an up to date copy of what's on production.

It's very ugly to look at but if I wait till it's cleaned up to post it
I'll end
up never posting it!

cheers,

Mike

desc "copy production database back to workstation"
task :dbpull, :roles => :db, :primary => true do
  # XXX this is really ugly code, clean it up
  require 'yaml'
  db_config = YAML.load_file("config/database.yml")
  dump_cmd = "mysqldump -u #{db_config['production']['username']}
-p#{db_config['production']['password']} --add-drop-table
--ignore-table=#{db_config['production']['database']}.sessions
--extended-insert=FALSE --complete-insert
#{db_config['production']['database']}"
  sql = []
  run cmd do |ssh_process, stream_identifier, data|
    # XXX must listen for data where stream_identifier = :err
    sql << data if stream_identifier == :out
  end

  # write it do a file
  File.open('/tmp/cap_sql_dump', 'w') do |file|
    file.write(sql)
    print '.'
  end

  # import data into development database (usually developers local
machine)
  password_switch = " -p #{db_config['development']['password']} " if
db_config['development']['password']
  cmd = "mysql -u #{db_config['development']['username']}
#{password_switch} #{db_config['development']['database']} <
/tmp/cap_sql_dump"
  exec cmd
end

On Oct 31, 1:03 am, Jason Perry <[EMAIL PROTECTED]> wrote:
> It's funny how things come together. This is from a chat with a
> friend 2 days ago.
>
>  > so a reverse SSH is one where you connect initially with the "-R"
> option to bind the servers port 22 to the SSH stream.
>  > so from the server, any outgoing traffic on port 22 (ssh) gets
> executed as if it were on the client
>  > so you can run "ssh -R 2048:localhost:22 othercomputer.com" from
> the client
>  > and then tunnel back with "ssh -p 2048 localhost"
>  > or better yet tunnel back with "ssh -D 8001 -p 2048 localhost"
>  > the trick/point of it all is to create a tunnel out of a NAT'ed or
> firewalled network, and then create a tunnel back into from the more
> accessible computer
>
> - Jason
>
> On Oct 29, 2006, at 11:20 PM, mike wrote:
>
> > Thanks Jason. That's something I hadn't thought of. I think I would
> > run into issues with NAT though when I'm on the road.
>
> > I'm going to see if I can add 'get' to capistrano. This has led me
> > to Jamis's
> > Net::SSH library which is really well documented and pretty exciting.


--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---

Reply via email to