Merge pull request #831 from sgmap/import_db_task
Rake task to import yesterday's production backup on dev
This commit is contained in:
commit
fc490f05e8
1 changed files with 21 additions and 0 deletions
|
@ -62,4 +62,25 @@ EOF
|
|||
file.write(content)
|
||||
file.close
|
||||
end
|
||||
|
||||
def run_and_stop_if_error(cmd)
|
||||
sh cmd do |ok, res|
|
||||
if !ok
|
||||
abort "#{cmd} failed with result : #{res.exitstatus}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
task :import_db do
|
||||
filename = "tps_prod_#{1.day.ago.strftime("%d-%m-%Y")}.sql"
|
||||
local_file = "/tmp/#{filename}"
|
||||
run_and_stop_if_error "scp deploy@sgmap_backup:/var/backup/production1/db/#{filename} #{local_file}"
|
||||
|
||||
Rake::Task["db:drop"].invoke
|
||||
Rake::Task["db:create"].invoke
|
||||
run_and_stop_if_error "psql tps_development -f #{local_file}"
|
||||
|
||||
Rake::Task["db:migrate"].invoke
|
||||
Rake::Task["db:environment:set"].invoke("RAILS_ENV=development")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue