Merge pull request #477 from hennevogel/master
Add a rake task to the deployment to backup the DB.
This commit is contained in:
commit
2cd5c83fc6
2 changed files with 18 additions and 1 deletions
|
|
@ -36,9 +36,10 @@ task deploy: :environment do
|
||||||
invoke :'git:clone'
|
invoke :'git:clone'
|
||||||
invoke :'deploy:link_shared_paths'
|
invoke :'deploy:link_shared_paths'
|
||||||
invoke :'bundle:install'
|
invoke :'bundle:install'
|
||||||
|
invoke :'dump_db'
|
||||||
invoke :'rails:db_migrate'
|
invoke :'rails:db_migrate'
|
||||||
invoke :'rails:assets_precompile'
|
invoke :'rails:assets_precompile'
|
||||||
invoke :notify_errbit
|
#invoke :notify_errbit
|
||||||
|
|
||||||
to :launch do
|
to :launch do
|
||||||
queue "sudo /etc/init.d/apache2 restart"
|
queue "sudo /etc/init.d/apache2 restart"
|
||||||
|
|
@ -55,3 +56,8 @@ task :notify_errbit do
|
||||||
user = ENV['USER']
|
user = ENV['USER']
|
||||||
queue "bundle exec rake hoptoad:deploy TO=#{rails_env} REVISION=#{revision} REPO=#{repository} USER=#{user}"
|
queue "bundle exec rake hoptoad:deploy TO=#{rails_env} REVISION=#{revision} REPO=#{repository} USER=#{user}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc 'Back ups the database'
|
||||||
|
task :dump_db do
|
||||||
|
queue "bundle exec rake dump_db"
|
||||||
|
end
|
||||||
|
|
|
||||||
11
lib/tasks/dump_db.rake
Normal file
11
lib/tasks/dump_db.rake
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
require 'yaml'
|
||||||
|
task :dump_db do
|
||||||
|
yaml = YAML.load_file("config/database.yml")
|
||||||
|
conf = yaml["production"]
|
||||||
|
filename = "#{conf["database"]}-#{Time.now.strftime("%Y-%m-%d-%H:%M:%S:%L")}.sql"
|
||||||
|
if conf["adapter"] == 'mysql2'
|
||||||
|
system "mysqldump -u #{conf["username"]} --password=#{conf["password"]} -h #{conf["host"]} #{conf["database"]} > ~/#{filename}"
|
||||||
|
else
|
||||||
|
puts "Error: This rake task only works for MYSQL"
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue