Skip to content

Commit

Permalink
Updated cap, added db backup task
Browse files Browse the repository at this point in the history
  • Loading branch information
zk committed Oct 15, 2010
1 parent 9327301 commit c8080e2
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Capfile
Expand Up @@ -41,4 +41,23 @@ after 'deploy:update_code', 'bundler:bundle_new_release'
task :update_sphinx, :role => [:web, :app] do
run("killall searchd; true")
run("cd #{deploy_to}/current && #{rake} thinking_sphinx:rebuild RAILS_ENV=production")
end
end

require 'yaml'

desc "Backup the remote production database"
task :backup, :roles => :db, :only => { :primary => true } do
filename = "#{application.downcase}.dump.#{Time.now.to_i}.sql.bz2"
file = "/tmp/#{filename}"
on_rollback { run "rm -f #{file}" }
db = YAML::load(ERB.new(IO.read(File.join(File.dirname(__FILE__), './config/database.yml'))).result)['production']
run "mysqldump -u #{db['username']} #{db['database']} | bzip2 -c > #{file}" do |ch, stream, data|
puts data
end
`mkdir -p ~/.#{application.downcase}_db_backups`
get file, File.expand_path("~/.#{application.downcase}_db_backups/#{filename}")
run "rm -f #{file}"
end

desc "Backup the database before running migrations"
before 'deploy:migrate', :backup

0 comments on commit c8080e2

Please sign in to comment.