From f212aeeb30f44cc755ec4fc657aadaeadf130daa Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 20 Aug 2014 00:49:48 +0200 Subject: [PATCH] Add a rake task to the deployment to backup the DB. Apparently needed with all the broken migrations... --- config/deploy.rb | 8 +++++++- lib/tasks/dump_db.rake | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 lib/tasks/dump_db.rake diff --git a/config/deploy.rb b/config/deploy.rb index aa1f020f..75f153c0 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -36,9 +36,10 @@ task deploy: :environment do invoke :'git:clone' invoke :'deploy:link_shared_paths' invoke :'bundle:install' + invoke :'dump_db' invoke :'rails:db_migrate' invoke :'rails:assets_precompile' - invoke :notify_errbit + #invoke :notify_errbit to :launch do queue "sudo /etc/init.d/apache2 restart" @@ -55,3 +56,8 @@ task :notify_errbit do user = ENV['USER'] queue "bundle exec rake hoptoad:deploy TO=#{rails_env} REVISION=#{revision} REPO=#{repository} USER=#{user}" end + +desc 'Back ups the database' +task :dump_db do + queue "bundle exec rake dump_db" +end diff --git a/lib/tasks/dump_db.rake b/lib/tasks/dump_db.rake new file mode 100644 index 00000000..6738f409 --- /dev/null +++ b/lib/tasks/dump_db.rake @@ -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