3 # DO NOT EDIT - This file is being maintained by Chef
8 # Get the name of the file and the expected pattern
10 pattern="^osm-([0-9]{4})-([0-9]{2})-([0-9]{2})\.dmp$"
12 # Give up now if the file isn't a database dump
13 [[ $file =~ $pattern ]] || exit 0
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]}"
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"
25 rm /tmp/planetdump.lock
30 echo $$ > /tmp/planetdump.lock
32 # Define cleanup function
34 rm /tmp/planetdump.lock
40 # Change to working directory
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
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"
57 # Function to install a dump in place
58 function install_dump {
63 name="${type}-${date}.osm.${format}"
64 latest="${type}-latest.osm.${format}"
66 md5sum "${name}" > "${name}.md5"
67 mkdir -p "${dir}/${year}"
68 mv "${name}" "${name}.md5" "${dir}/${year}"
69 ln -sf "${year:-.}/${name}" "${dir}/${latest}"
70 rm -f "${dir}/${latest}.md5"
71 sed -e "s/${name}/${latest}/" > "${dir}/${year}/${name}.md5" > "${dir}/${latest}.md5"
74 # Move dumps into place
75 install_dump "changesets" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "${year}"
76 install_dump "planet" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "${year}"
77 install_dump "history" "bz2" "<%= node[:planet][:dump][:xml_history_directory] %>" "${year}"
78 install_dump "planet" "pbf" "<%= node[:planet][:dump][:pbf_directory] %>"
79 install_dump "history" "pbf" "<%= node[:planet][:dump][:pbf_history_directory] %>"