]> git.openstreetmap.org Git - chef.git/blob - cookbooks/overpass/templates/default/overpass-import-db.erb
add overpass cookbook
[chef.git] / cookbooks / overpass / templates / default / overpass-import-db.erb
1 #!/bin/bash -e
2
3 FNAME=$1
4
5 if [[ "x$FNAME" == "x" ]]; then
6   echo "Usage: overpass-import-db.sh <OSM file>"
7   exit 1
8 fi
9
10 case "$FNAME" in
11   *.gz) UNPACKER='gunzip -c' ;;
12   *.bz2) UNPACKER='bunzip2 -c' ;;
13   *) UNPACKER='osmium cat -o - -f xml' ;;
14 esac
15
16 <% if node[:overpass][:meta_mode] == "meta" -%>
17 META=--meta
18 <% elsif node[:overpass][:meta_mode] == "attic" -%>
19 META=--keep-attic
20 <% else -%>
21 META=
22 <% end -%>
23
24 sudo systemctl stop overpass-area-processor.timer
25 sudo systemctl stop overpass-update
26 sudo systemctl stop overpass-area-dispatcher
27 sudo systemctl stop overpass-dispatcher
28
29 sleep 2
30
31 # Remove old database
32 sudo -u <%= @username %> rm -rf <%= @basedir %>/db/*
33
34 $UNPACKER $FNAME | sudo -u <%= @username %> <%= @basedir %>/bin/update_database --db-dir='<%= @basedir %>/db' --compression-method=<%= node[:overpass][:compression_mode] %> --map-compression-method=<%= node[:overpass][:compression_mode] %> $META
35
36 sudo -u <%= @username %> ln -s <%= @srcdir %>/rules <%= @basedir %>/db/rules
37
38 echo "Import finished. Catching up with new changes."
39
40 sudo systemctl start overpass-dispatcher
41 sudo systemctl start overpass-area-dispatcher
42
43 PYOSMIUM="sudo -u <%= @username %> pyosmium-get-changes --server <%= node[:overpass][:replication_url] %> -f <%= @basedir %>/db/replicate-id"
44 <% if node[:overpass][:meta_mode] == "attic" -%>
45 PYOSMIUM="$PYOSMIUM --no-deduplicate"
46 <% end -%>
47
48 # Get the replication id
49 $PYOSMIUM -v -O $FNAME --ignore-osmosis-headers
50
51 sudo -u <%= @username %> rm -f <%= @basedir %>/diffs/*
52
53 while $PYOSMIUM -v -s 1000 -o <%= @basedir %>/diffs/latest.osc; do
54   if [ ! -f <%= @basedir %>/db/replicate-id ]; then
55     echo "Replication ID not written."
56     exit 1
57   fi
58   DATA_VERSION=`osmium fileinfo -e -g data.timestamp.last <%= @basedir %>/diffs/latest.osc`
59   echo "Downloaded up to timestamp $DATA_VERSION"
60   while ! sudo -u <%= @username %> <%= @basedir %>/bin/update_from_dir --osc-dir=<%= @basedir %>/diffs --version=$DATA_VERSION $META --flush-size=0; do
61     echo "Error while updating. Retry in 1 min."
62     sleep 60
63   done
64   sudo -u <%= @username %> rm <%= @basedir %>/diffs/latest.osc
65   echo "Finished up to $DATA_VERSION."
66 done
67
68 echo "DB up-to-date. Processing areas."
69
70 sudo -u <%= @username %> <%= @basedir %>/bin/osm3s_query --progress --rules <<%= @srcdir %>/rules/areas.osm3s
71
72 echo "All updates done."
73
74 sudo systemctl start overpass-area-processor.timer