Skip to content

Instantly share code, notes, and snippets.

@bishopandco
Created June 16, 2010 17:22
Show Gist options
  • Save bishopandco/440984 to your computer and use it in GitHub Desktop.
Save bishopandco/440984 to your computer and use it in GitHub Desktop.
namespace(:db) do
desc "Pulls remote DB and saves to file."
task :pull, :roles => :web do
load 'config/environment.rb'
abcs = ActiveRecord::Base.configurations
curr_date = Time.new
timestamp = curr_date.mon.to_s + "_" + curr_date.day.to_s + "_" + curr_date.hour.to_s + "_" + curr_date.min.to_s
run "mysqldump -h#{abcs[stage.to_s]["host"]} -u#{abcs[stage.to_s]["username"]} --password=#{abcs[stage.to_s]["password"]} #{abcs[stage.to_s]["database"]} > #{shared_path}/#{stage.to_s}_data_#{timestamp}.sql"
run "cd #{shared_path} && tar -czvf #{shared_path}/#{stage.to_s}_data_#{timestamp}.sql.tar.gz #{stage.to_s}_data_#{timestamp}.sql"
run "rm #{shared_path}/#{stage.to_s}_data_#{timestamp}.sql"
download "#{shared_path}/#{stage.to_s}_data_#{timestamp}.sql.tar.gz","#{stage.to_s}_data_#{timestamp}.sql.tar.gz", :via => :scp, :roles => :db
run "rm #{shared_path}/#{stage.to_s}_data_#{timestamp}.sql.tar.gz"
system "tar -xvzf #{stage.to_s}_data_#{timestamp}.sql.tar.gz"
system "rm #{stage.to_s}_data_#{timestamp}.sql.tar.gz"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment