Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add port option for the mysql #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added support for custome port as well
  • Loading branch information
devilankur18 committed May 14, 2013
commit 73668f25a3ad52663e49a3a16b4de9b58cafca00
15 changes: 9 additions & 6 deletions lib/capistrano/mysqldump.rb
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@
dump
import
end

task :setup do
set :mysqldump_config, YAML.load_file("config/database.yml")[rails_env.to_s]
set :mysqldump_config, YAML.load_file("config/database.yml")[rails_env.to_s]
host = mysqldump_config["host"]

# overwrite these if necessary
@@ -24,12 +24,13 @@
end

task :dump, :roles => :db do
setup
username, password, database, host = mysqldump_config.values_at *%w( username password database host )
setup
username, password, database, host, port = mysqldump_config.values_at *%w( username password database host port)

mysqldump_cmd = "%s --quick --single-transaction" % mysqldump_bin
mysqldump_cmd += " -h #{host}" if host && !host.empty?

mysqldump_cmd += " -P #{port}" if port && !port.to_s.empty?

case mysqldump_location
when :remote
mysqldump_cmd += " -u %s -p %s" % [ username, database ]
@@ -41,13 +42,15 @@

download mysqldump_remote_filename, mysqldump_local_filename_gz, :via => :scp
run "rm #{mysqldump_remote_filename}"


puts "gunzip #{mysqldump_local_filename_gz}"
`gunzip #{mysqldump_local_filename_gz}`
when :local
mysqldump_cmd += " -u %s" % username
mysqldump_cmd += " -p#{password}" if password && !password.empty?
mysqldump_cmd += " %s > %s" % [ database, mysqldump_local_filename]

puts mysqldump_cmd
`#{mysqldump_cmd}`
end
end