diff options
| author | mo khan <mo@mokhan.ca> | 2013-11-10 09:49:09 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-11-10 09:49:09 -0700 |
| commit | ad9b357bbf12a8e26d774f52f52c1b0de69ad2a4 (patch) | |
| tree | 157c2898a8f001ac00aeb6c6fe3b9d2915fe57ba /lib/tasks | |
| parent | fb43dbf00a24220035e9b50814d80851c4f89583 (diff) | |
fix rake db:restore task.
Diffstat (limited to 'lib/tasks')
| -rw-r--r-- | lib/tasks/database.rake | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/lib/tasks/database.rake b/lib/tasks/database.rake index c2f10bc0..f61e56f7 100644 --- a/lib/tasks/database.rake +++ b/lib/tasks/database.rake @@ -1,16 +1,13 @@ namespace :db do task :restore do - dumpfile = "latest" config = Rails.configuration.database_configuration destination_db = config[Rails.env]["database"] - puts "restoring to #{destination_db}" - sh "psql #{destination_db} < #{dumpfile}" - #sh "pg_restore --verbose --clean --no-acl --no-owner -h localhost -U #{config[Rails.env]["username"]} -d #{destination_db} #{dumpfile}" + + newest_backup = Dir['db/backups/*.dump'].max_by { |file| File.mtime(file) } + sh "PGPASSWORD=#{config[Rails.env]["password"]} pg_restore --verbose --clean --no-acl --no-owner -h localhost -U #{config[Rails.env]["username"]} -d #{destination_db} #{newest_backup}" end task :backup do - puts "Please specify RAILS_ENV:"; return unless ENV['RAILS_ENV'] - puts "backup up #{ENV['RAILS_ENV']}" sh "cap #{ENV['RAILS_ENV']} postgresql:backup" end |
