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