Created
April 9, 2013 07:00
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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