Skip to content

Instantly share code, notes, and snippets.

@rjsvaljean
Created November 14, 2009 11:24
Show Gist options
  • Select an option

  • Save rjsvaljean/234481 to your computer and use it in GitHub Desktop.

Select an option

Save rjsvaljean/234481 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
require 'rubygems'
require 'net/ssh'
require 'net/ssh/proxy/http'
local_host = "localhost"
local_port = "5444"
username = "test"
password = "passowrd"
remote_host = "ssh.example.com"
remote_port = "3306"
proxy = Net::SSH::Proxy::HTTP.new('144.16.192.245',8080)
db_user = 'db_user'
db_password = 'db_pass'
thread = Thread.new do
Net::SSH.start(remote_host,username, :password => password, :proxy => proxy) do |ssh|
ssh.forward.local(local_port,local_host,remote_port)
ssh.loop{ true }
end
end
# Ugly! Ugly! TODO: find alternate way to make sure that the tunnel has been established.
`sleep 10`
`mysqldump -u#{db_user} -p#{db_password} --host=127.0.0.1 --port=#{local_port} test_database > test.sql`
thread.kill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment