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
 
  29 # Redirect this shell's output to a file. This is so that it
 
  30 # can be emailed later, since this script is run from incron
 
  31 # and incron doesn't yet support MAILTO like cron does. The
 
  32 # command below appears to work in bash as well as dash.
 
  33 logfile="/tmp/planetdump.log.$$"
 
  34 exec > "${logfile}" 2>&1
 
  37 echo $$ > /tmp/planetdump.lock
 
  39 # Define cleanup function
 
  41     # Remove the lock file
 
  42     rm /tmp/planetdump.lock
 
  44     # Send an email with the output, since incron doesn't yet
 
  45     # support doing this in the incrontab
 
  46     if [[ -s "$logfile" ]]
 
  48         mailx -s "Planet dump output: ${file}" zerebubuth@gmail.com < "${logfile}"
 
  58 # Change to working directory
 
  63 rm -rf changesets changeset_tags changeset_comments
 
  64 rm -rf nodes node_tags
 
  65 rm -rf ways way_tags way_nodes
 
  66 rm -rf relations relation_tags relation_members
 
  69 time nice -n 19 /opt/planet-dump-ng/planet-dump-ng \
 
  71      -c "pbzip2 -c" -f "/store/backup/${file}" --dense-nodes=1 \
 
  72      -C "changesets-${date}.osm.bz2" \
 
  73      -D "discussions-${date}.osm.bz2" \
 
  74      -x "planet-${date}.osm.bz2" -X "history-${date}.osm.bz2" \
 
  75      -p "planet-${date}.osm.pbf" -P "history-${date}.osm.pbf"
 
  77 # Function to create bittorrent files
 
  82   name="${type}-${date}.osm.${format}"
 
  83   web_path="${web_dir}/${name}"
 
  85   mktorrent -l 22 ${name} \
 
  86      -a udp://tracker.opentrackr.org:1337 \
 
  87      -a udp://tracker.datacenterlight.ch:6969/announce,http://tracker.datacenterlight.ch:6969/announce \
 
  88      -a udp://tracker.torrent.eu.org:451 \
 
  89      -a udp://tracker-udp.gbitt.info:80/announce,http://tracker.gbitt.info/announce,https://tracker.gbitt.info/announce \
 
  90      -a http://retracker.local/announce \
 
  91      -w https://planet.openstreetmap.org/${web_path} \
 
  92      -w https://ftp5.gwdg.de/pub/misc/openstreetmap/planet.openstreetmap.org/${web_path} \
 
  93      -w https://ftpmirror.your.org/pub/openstreetmap/${web_path} \
 
  94      -w https://mirror.init7.net/openstreetmap/${web_path} \
 
  95      -w https://free.nchc.org.tw/osm.planet/${web_path} \
 
  96      -w https://ftp.fau.de/osm-planet/${web_path} \
 
  97      -w https://ftp.spline.de/pub/openstreetmap/${web_path} \
 
  98      -w https://osm.openarchive.site/${name} \
 
  99      -w https://downloads.opencagedata.com/planet/${name} \
 
 100      -w https://planet.osm-hr.org/${web_path} \
 
 101      -c "OpenStreetMap ${type} data export, licensed under https://opendatacommons.org/licenses/odbl/ by OpenStreetMap contributors" \
 
 105 # Function to install a dump in place
 
 106 function install_dump {
 
 111   name="${type}-${date}.osm.${format}"
 
 112   latest="${type}-latest.osm.${format}"
 
 114   md5sum "${name}" > "${name}.md5"
 
 115   mkdir -p "${dir}/${year}"
 
 116   mv "${name}" "${name}.md5" "${dir}/${year}"
 
 117   ln -sf "${year:-.}/${name}" "${dir}/${latest}"
 
 118   test -f "${name}.torrent" && mv "${name}.torrent" "${dir}/${year}" && ln -sf "${year:-.}/${name}.torrent" "${dir}/${latest}.torrent"
 
 119   rm -f "${dir}/${latest}.md5"
 
 120   sed -e "s/${name}/${latest}/" "${dir}/${year}/${name}.md5" > "${dir}/${latest}.md5"
 
 123 # Create *.torrent files
 
 124 mk_torrent "changesets" "bz2" "planet/${year}"
 
 125 mk_torrent "discussions" "bz2" "planet/${year}"
 
 126 mk_torrent "planet" "bz2" "planet/${year}"
 
 127 mk_torrent "history" "bz2" "planet/full-history/${year}"
 
 128 mk_torrent "planet" "pbf" "pbf"
 
 129 mk_torrent "history" "pbf" "pbf/full-history"
 
 131 # Move dumps into place
 
 132 install_dump "changesets" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "${year}"
 
 133 install_dump "discussions" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "${year}"
 
 134 install_dump "planet" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "${year}"
 
 135 install_dump "history" "bz2" "<%= node[:planet][:dump][:xml_history_directory] %>" "${year}"
 
 136 install_dump "planet" "pbf" "<%= node[:planet][:dump][:pbf_directory] %>"
 
 137 install_dump "history" "pbf" "<%= node[:planet][:dump][:pbf_history_directory] %>"
 
 139 # Remove pbf dumps older than 90 days
 
 140 find "<%= node[:planet][:dump][:pbf_directory] %>" "<%= node[:planet][:dump][:pbf_history_directory] %>" \
 
 141      -maxdepth 1 -mindepth 1 -type f -mtime +90 \
 
 143      -iname 'planet-*.pbf' \
 
 144      -o -iname 'history-*.pbf' \
 
 145      -o -iname 'planet-*.pbf.md5' \
 
 146      -o -iname 'history-*.pbf.md5' \