Skip to content

Instantly share code, notes, and snippets.

@erochest
Created November 14, 2012 14:00
Show Gist options
  • Save erochest/4072257 to your computer and use it in GitHub Desktop.
Save erochest/4072257 to your computer and use it in GitHub Desktop.
Upgrade PostGIS tables.
def pg_restore(dbname)
filename = "#{DUMP_DIR}/#{dbname}.dump"
vm_dump_file = "/vagrant/#{DUMP_DIR}/#{dbname}.dump"
log_file = "/vagrant/#{DUMP_DIR}/#{dbname}.log"
puts "Restoring/Upgrading #{filename} (#{vm_dump_file}) => #{dbname}"
start = Time.now
env = Vagrant::Environment.new
puts "logging to #{log_file}"
vm_ssh(env, "sh /usr/share/postgresql-9.1-postgis/utils/postgis_restore.pl /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql #{dbname} #{vm_dump_file} -E=UNICODE > #{log_file}")
vm_ssh(env, "grep ^KEEPING #{log_file}")
# May need to re-create the spatial_ref_sys table:
#
# psql db_name
# truncate spatial_ref_sys;
# \i /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql
# \q
#
# If there are customizations, they'll need to be re-added separately.
puts "mv #{filename} dumps/done"
FileUtils.mv(filename, 'dumps/done')
done = Time.now
puts "[#{dbname}] DONE. Elapsed: #{(done - start) * 1000.0} sec."
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment