Skip to content

Instantly share code, notes, and snippets.

@stenehall
Created April 9, 2013 07:00
Show Gist options
  • Save stenehall/5343571 to your computer and use it in GitHub Desktop.
Save stenehall/5343571 to your computer and use it in GitHub Desktop.
Put pushDatabase and pullDatabase in your ~/bin folder. I've removed the extension for easier access.
#!/usr/bin/env ruby
# encoding: utf-8
require 'rubygems'
require 'net/ssh'
require 'rainbow'
if ARGV[0] && ! ARGV[0].empty?
name = ARGV[0]
db_output = %x[ssh {} 'mysql -u{server user} -p{server password} -e "SHOW DATABASES"']
db_output.each_line do |db|
if ! db.empty?
db = db.rstrip
if db != "information_schema" && db != "Database" && (db.include? name) then
puts "Found database [#{db}], do you want to continue [N/y]".color(:green)
response = STDIN.gets
if response.chomp.strip == "y"
puts "Pulling database: #{db}".color(:green)
%x[cd /tmp && ssh {server} 'mysqldump -u{change} -p{change} --add-drop-table #{db} | gzip -v -9' > #{db}.sql.gz && gunzip < #{db}.sql.gz | mysql -u{change} -p{change} #{db}]
else
puts "Stop".color(:red)
end
break
end
end
end
else
puts 'You have to provide a project name'.color(:red)
end
#!/usr/bin/env ruby
# encoding: utf-8
require 'rubygems'
require 'net/ssh'
require 'rainbow'
if ARGV[0] && ! ARGV[0].empty? then
name = ARGV[0]
db_output = %x[/Applications/MAMP/Library/bin/mysql -u{change to your user} -p{change to your password} -e "SHOW DATABASES"]
db_output.each_line do |db|
if ! db.empty? then
db = db.rstrip
if db != "information_schema" && db != "Database" && (db.include? name) then
puts "Pushing database: #{db}".color(:red)+", do you want to continue [N/y]".color(:green)
response = STDIN.gets
if response.chomp.strip == "y" then
puts "Pushing database: #{db}".color(:green)
%x[cd /tmp && /Applications/MAMP/Library/bin/mysqldump -u{change} -p{change} --add-drop-table #{db} | gzip -v -9 > #{db}.sql.gz && ssh {change to your server} 'gunzip | mysql -u{change to your servers user} -p{change to your servers password} #{db}' < #{db}.sql.gz]
else
puts "Stop".color(:red)
end
break
end
end
end
else
puts 'You have to provide a project name'.color(:red)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment