diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | config/recipes/postgresql.rb | 25 | ||||
| -rw-r--r-- | lib/tasks/database.rake | 5 |
3 files changed, 12 insertions, 19 deletions
@@ -11,7 +11,6 @@ NERD_tree_* tags .sass-cache/ *.fuse* -latest config/database.yml coverage .vagrant diff --git a/config/recipes/postgresql.rb b/config/recipes/postgresql.rb index 57509e4d..c27e1d77 100644 --- a/config/recipes/postgresql.rb +++ b/config/recipes/postgresql.rb @@ -33,24 +33,17 @@ namespace :postgresql do end after "deploy:finalize_update", "postgresql:symlink" - task :backup do - filename = "#{rails_env}-#{Time.now.strftime('%Y-%m-%d')}.sql" - run "pg_dump --clean #{postgresql_database} > ~/db/backups/#{filename}" - #run "PGPASSWORD=password pg_dump -Fc --no-acl --no-owner -h localhost -U cakeside cakeside_production > ~/db/backups/#{filename}" - download("db/backups/#{filename}", "db/backups/", :via => :scp, :recursive => true) + desc "Backup the database and copy it locally" + task :backup, roles: :db, only: {primary: true} do + filename = "#{rails_env}-#{Time.now.strftime('%Y-%m-%d-%H-%M')}.dump" + backup_path = "#{shared_path}/backups" + run "mkdir -p #{shared_path}/backups" + + run "PGPASSWORD='#{postgresql_password}' pg_dump -Fc --no-acl --no-owner -h #{postgresql_host} -U #{postgresql_user} #{postgresql_database} > #{backup_path}/#{filename}" + download("#{backup_path}/#{filename}", "db/backups/", :via => :scp) + run_locally "cd tmp; rm database.dump; ln -s #{filename} database.dump" end - #desc "Backup the database and copy it locally" - #task :backup, roles: :db, only: {primary: true} do - #filename = "#{rails_env}-#{Time.now.strftime('%Y-%m-%d-%H-%M')}.dump" - #backup_path = "#{shared_path}/backups" - #run "mkdir -p #{shared_path}/backups" - - #run "PGPASSWORD='#{postgresql_password}' pg_dump -Fc --no-acl --no-owner -h #{postgresql_host} -U #{postgresql_user} #{postgresql_database} > #{backup_path}/#{filename}" - #download("#{backup_path}/#{filename}", "tmp/#{filename}", :via => :scp) - #run_locally "cd tmp; rm database.dump; ln -s #{filename} database.dump" - #end - task :restore do dumpfile = "~/db/backups/latest" upload("latest", "db/backups/latest", :via => :scp) diff --git a/lib/tasks/database.rake b/lib/tasks/database.rake index 61c3914c..c2f10bc0 100644 --- a/lib/tasks/database.rake +++ b/lib/tasks/database.rake @@ -9,8 +9,9 @@ namespace :db do end task :backup do - sh "cap production postgresql:backup" - sh "rm -f latest && ln -s db/backups/`ls -rt db/backups/ | tail -n1` latest" + puts "Please specify RAILS_ENV:"; return unless ENV['RAILS_ENV'] + puts "backup up #{ENV['RAILS_ENV']}" + sh "cap #{ENV['RAILS_ENV']} postgresql:backup" end task :restore_to_staging => :backup do |
