Created
January 29, 2014 09:57
-
-
Save Yago/90e5f0dec573c9544893 to your computer and use it in GitHub Desktop.
Capistrano - DB deployer
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
# SERVER | |
set :domain, "yago.webfactional.com" | |
set :user, "yago" | |
# NAME | |
set :application, "yago" | |
# REPOSITORY | |
set :repository, "[email protected]:Yago31/yago-site.git" | |
server "#{domain}", :app, :web, :db, :primary => true | |
set :deploy_via, :copy | |
set :copy_exclude, [".git", ".DS_Store"] | |
set :scm, :git | |
set :branch, "master" | |
# set this path to be correct on yoru server | |
set :deploy_to, "/home/yago/webapps/#{application}" | |
set :use_sudo, false | |
set :keep_releases, 2 | |
set :git_shallow_clone, 1 | |
set :keep_releases, 10 | |
ssh_options[:paranoid] = false | |
# DATABASE | |
set :dumpname, "dump.#{Time.now.strftime '%Y%m%d%H%M%S'}.sql" | |
set :dbuser, "yago" | |
set :dbhost, "web370.webfaction.com" | |
set :dbpassword, "PASSWORD" | |
set :application_db, "yago" | |
set :local_db_host, "localhost" | |
set :local_db_user, "root" | |
set :local_db_password, "" | |
set :local_db, "yago" | |
namespace :deploy do | |
desc <<-DESC | |
A macro-task that updates the code and fixes the symlink. | |
DESC | |
task :default do | |
transaction do | |
update_code | |
symlink | |
end | |
end | |
task :update_code, :except => { :no_release => true } do | |
on_rollback { run "rm -rf #{release_path}; true" } | |
strategy.deploy! | |
end | |
task :after_deploy do | |
cleanup | |
end | |
end | |
namespace :database do | |
desc "Load production DB into Staging DB" | |
task :importdb do | |
system "mysqldump -u #{local_db_user} -B #{local_db} > dump/#{dumpname}" | |
system "ssh -C #{user}@#{domain} mysql -u #{dbuser} --password=#{dbpassword} #{application_db} < dump/#{dumpname}" | |
end | |
end | |
namespace :config do | |
desc "Load production DB into Staging DB" | |
task :config_file do | |
run "rm #{release_path}/anchor/config/db.php" | |
run "cp #{release_path}/anchor/config/db.php.dist #{release_path}/anchor/config/db.php" | |
run "rm #{release_path}/anchor/config/db.php.dist" | |
end | |
end | |
before "deploy:update_code", "database:importdb" | |
after "deploy:update_code", "config:config_file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment