]> git.openstreetmap.org Git - chef.git/blob - cookbooks/planet/templates/default/planetdump.erb
Extracted all references to planet dump output locations to attributes
[chef.git] / cookbooks / planet / templates / default / planetdump.erb
1 #!/bin/bash
2 # DO NOT EDIT - This file is being maintained by Chef
3
4 # Exit on error
5 set -e
6
7 # Get the name of the file and the expected pattern
8 file="$1"
9 pattern="^osm-([0-9]{4}-[0-9]{2}-[0-9]{2})\.dmp$"
10
11 # Give up now if the file isn't a database dump
12 [[ $file =~ $pattern ]] || exit 0
13
14 # Save the date from the file name
15 date="${BASH_REMATCH[1]}"
16
17 # Check the lock
18 if [ -f /tmp/planetdump.lock ]; then
19     if [ "$(ps -p `cat /tmp/planetdump.lock` | wc -l)" -gt 1 ]; then
20         echo "Error: Another planetdump is running"
21         exit 1
22     else
23         rm /tmp/planetdump.lock
24     fi
25 fi
26
27 # Create Lock
28 echo $$ > /tmp/planetdump.lock
29
30 function cleanup {
31          # Release lock
32          rm /tmp/planetdump.lock
33 }
34
35 # Remove lock on exit
36 trap cleanup EXIT
37
38 # Change to working directory
39 cd /store/planetdump
40
41 # Cleanup
42 rm -rf users
43 rm -rf changesets changeset_tags
44 rm -rf nodes node_tags
45 rm -rf ways way_tags way_nodes
46 rm -rf relations relation_tags relation_members
47
48 # Run the dump
49 time nice -n 19 /store/planet-dump-ng/planet-dump-ng \
50      -c "pbzip2 -c" -f "${file}" --dense-nodes=1 \
51      -C "changesets-${date}.osm.bz2" \
52      -x "planet-${date}.osm.bz2" -X "history-${date}.osm.bz2" \
53      -p "planet-${date}.osm.pbf" -P "history-${date}.osm.pbf"
54
55 # Move XML dumps into place
56 year = `echo ${date} | sed "s/.*-\([0-9]\)\{4\}-.*/\1/"`
57 <% {
58          "changesets-${date}.osm.bz2" => "#{node[:planet][:dump][:xml_directory]}/${year}",
59          "planet-${date}.osm.bz2" => "#{node[:planet][:dump][:xml_directory]}/${year}",
60          "history-${date}.osm.bz2" => "#{node[:planet][:dump][:xml_history_directory]}/${year}",
61          "planet-${date}.osm.pbf" => node[:planet][:dump][:pbf_directory],
62          "history-${date}.osm.pbf" => node[:planet][:dump][:pbf_history_directory]
63 }.each do |file,dir| %>
64 md5sum "<%= file %>" > "<%= file %>.md5"
65 mv "<%= file %>" "<%= file %>.md5" "<%= dir %>"
66 <% end %>