Commit c9a5d761

mo khan <mo@mokhan.ca>
2013-11-10 16:16:23
fix postgres backup task.
1 parent 155200d
Changed files (3)
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)
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
.gitignore
@@ -11,7 +11,6 @@ NERD_tree_*
 tags
 .sass-cache/
 *.fuse*
-latest
 config/database.yml
 coverage
 .vagrant