]> git.openstreetmap.org Git - chef.git/blob - cookbooks/planet/templates/default/planetdump.erb
Do not report progress on scripted s3 uploads
[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 file
30 echo $$ > /tmp/planetdump.lock
31
32 # Define cleanup function
33 function cleanup {
34     # Remove the lock file
35     rm /tmp/planetdump.lock
36 }
37
38 # Remove lock on exit
39 trap cleanup EXIT
40
41 # Change to working directory
42 cd /store/planetdump
43
44 # Cleanup
45 rm -rf users
46 rm -rf changesets changeset_tags changeset_comments
47 rm -rf nodes node_tags
48 rm -rf ways way_tags way_nodes
49 rm -rf relations relation_tags relation_members
50
51 # Run the dump
52 time nice -n 19 /opt/planet-dump-ng/planet-dump-ng \
53      --max-concurrency=4 \
54      -c "pbzip2 -c" -f "/store/backup/${file}" --dense-nodes=1 \
55      -C "changesets-${date}.osm.bz2" \
56      -D "discussions-${date}.osm.bz2" \
57      -x "planet-${date}.osm.bz2" -X "history-${date}.osm.bz2" \
58      -p "planet-${date}.osm.pbf" -P "history-${date}.osm.pbf"
59
60 # Function to create bittorrent files
61 function mk_torrent {
62   type="$1"
63   format="$2"
64   dir="$3"
65   s_year="$4"
66   web_dir="${dir}${s_year}"
67   name="${type}-${date}.osm.${format}"
68   web_path="${web_dir}/${name}"
69   rss_web_dir="https://planet.openstreetmap.org/${dir}"
70   rss_file="${type}-${format}-rss.xml"
71   torrent_file="${name}.torrent"
72   torrent_url="${rss_web_dir}${s_year}/${torrent_file}"
73
74   # create .torrent file
75   mktorrent -l 22 "${name}" \
76      -a udp://tracker.opentrackr.org:1337 \
77      -a udp://tracker.datacenterlight.ch:6969/announce,http://tracker.datacenterlight.ch:6969/announce \
78      -a udp://tracker.torrent.eu.org:451 \
79      -a udp://tracker-udp.gbitt.info:80/announce,http://tracker.gbitt.info/announce,https://tracker.gbitt.info/announce \
80      -a http://retracker.local/announce \
81      -w "https://planet.openstreetmap.org/${web_path}" \
82      -w "https://ftp5.gwdg.de/pub/misc/openstreetmap/planet.openstreetmap.org/${web_path}" \
83      -w "https://ftpmirror.your.org/pub/openstreetmap/${web_path}" \
84      -w "https://mirror.init7.net/openstreetmap/${web_path}" \
85      -w "https://ftp.fau.de/osm-planet/${web_path}" \
86      -w "https://ftp.spline.de/pub/openstreetmap/${web_path}" \
87      -w "https://downloads.opencagedata.com/planet/${name}" \
88      -w "https://planet.osm-hr.org/${web_path}" \
89      -w "https://planet.maps.mail.ru/${web_path}" \
90      -c "OpenStreetMap ${type} data export, licensed under https://opendatacommons.org/licenses/odbl/ by OpenStreetMap contributors" \
91      -o "${torrent_file}" > /dev/null
92
93   # create .xml global RSS headers if missing
94   torrent_time_rfc="$(date -R -r ${torrent_file})"
95   test -f "${rss_file}" || echo "<x/>" | xmlstarlet select --xml-decl --indent \
96         -N "atom=http://www.w3.org/2005/Atom" \
97         -N "dcterms=http://purl.org/dc/terms/" \
98         -N "content=http://purl.org/rss/1.0/modules/content/" \
99         --encode "UTF-8" \
100         --template \
101         --match / \
102         --elem "rss" \
103                 --attr "version" --output "2.0" --break \
104                 --attr "atom:DUMMY" --break \
105         --elem "channel" \
106         --elem "title" --output "OpenStreetMap ${type} ${format} torrent RSS" --break \
107         --elem "link"  --output "${rss_web_dir}" --break \
108         --elem "atom:link" \
109                 --attr "href" --output "${rss_web_dir}/${rss_file}" --break \
110                 --attr "rel" --output "self" --break \
111                 --attr "type" --output "application/rss+xml" --break \
112                 --break \
113         --elem "description" --output "${type}.osm.${format}.torrent RSS feed" --break \
114         --elem "copyright" --output "Source: OpenStreetMap contributors, under ODbL 1.0 licence" --break \
115         --elem "generator" --output "OpenStreetMap xmlstarlet powered shell script v1.0" --break \
116         --elem "language" --output "en" --break \
117         --elem "lastBuildDate" --output "${torrent_time_rfc}" \
118         > "${rss_file}"
119
120   # add newly created .torrent file as new entry to .xml RSS feed, removing excess entries
121   torrent_size="$(stat --format="%s" ${torrent_file})"
122   xmlstarlet edit --inplace \
123         -a "//lastBuildDate" -t elem -n item -v ""  \
124         -s "//item[1]" -t elem -n "title" -v "${torrent_file}" \
125         -s "//item[1]" -t elem -n "guid" -v "${torrent_url}" \
126         -s "//item[1]" -t elem -n "link" -v "${torrent_url}" \
127         -s "//item[1]" -t elem -n "pubDate" -v "${torrent_time_rfc}" \
128         -s "//item[1]" -t elem -n "category" -v "OpenStreetMap data" \
129         -s "//item[1]" -t elem -n "enclosure" \
130                 -s "//item[1]"/enclosure -t attr -n "type" -v "application/x-bittorrent" \
131                 -s "//item[1]"/enclosure -t attr -n "length" -v "${torrent_size}" \
132                 -s "//item[1]"/enclosure -t attr -n "url" -v "${torrent_url}" \
133         -s "//item[1]" -t elem -n "description" -v "OpenStreetMap torrent ${torrent_file}" \
134         -u /rss/channel/lastBuildDate -v "${torrent_time_rfc}" \
135         -d /rss/@atom:DUMMY \
136         -d "//item[position()>5]" \
137         "${rss_file}"
138 }
139
140 # Function to install a dump in place
141 function install_dump {
142   type="$1"
143   format="$2"
144   dir="$3"
145   s3dir="$4"
146   year="$5"
147   name="${type}-${date}.osm.${format}"
148   latest="${type}-latest.osm.${format}"
149   rss_file="${type}-${format}-rss.xml"
150
151   md5sum "${name}" > "${name}.md5"
152   mkdir -p "${dir}/${year}"
153   mv "${name}" "${name}.md5" "${dir}/${year}"
154   ln -sf "${year:-.}/${name}" "${dir}/${latest}"
155   test -f "${name}.torrent" && mv "${name}.torrent" "${dir}/${year}" && ln -sf "${year:-.}/${name}.torrent" "${dir}/${latest}.torrent"
156   test -f "${rss_file}" && xmllint --noout "${rss_file}" && cp -f "${rss_file}" "${dir}"
157   rm -f "${dir}/${latest}.md5"
158   sed -e "s/${name}/${latest}/" "${dir}/${year}/${name}.md5" > "${dir}/${latest}.md5"
159
160   /opt/awscli/v2/current/bin/aws --profile=osm-pds-upload s3 cp --storage-class=INTELLIGENT_TIERING  --no-progress "${dir}/${year}/${name}.md5" "${s3dir}/${name}.md5"
161   /opt/awscli/v2/current/bin/aws --profile=osm-pds-upload s3 cp --storage-class=INTELLIGENT_TIERING  --no-progress "${dir}/${year}/${name}" "${s3dir}/${name}"
162   /opt/awscli/v2/current/bin/aws --profile=osm-pds-upload s3 cp --storage-class=INTELLIGENT_TIERING  --no-progress "${dir}/${year}/${name}.torrent" "${s3dir}/${name}.torrent"
163 }
164
165 # Create *.torrent files
166 mk_torrent "changesets" "bz2" "planet" "/${year}"
167 mk_torrent "discussions" "bz2" "planet" "/${year}"
168 mk_torrent "planet" "bz2" "planet" "/${year}"
169 mk_torrent "history" "bz2" "planet/full-history" "/${year}"
170 mk_torrent "planet" "pbf" "pbf"
171 mk_torrent "history" "pbf" "pbf/full-history"
172
173 # Move dumps into place
174 install_dump "changesets" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "s3://osm-planet-eu-central-1/changesets/osm/${year}" "${year}"
175 install_dump "discussions" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "s3://osm-planet-eu-central-1/discussions/osm/${year}" "${year}"
176 install_dump "planet" "bz2" "<%= node[:planet][:dump][:xml_directory] %>" "s3://osm-planet-eu-central-1/planet/osm/${year}" "${year}"
177 install_dump "history" "bz2" "<%= node[:planet][:dump][:xml_history_directory] %>" "s3://osm-planet-eu-central-1/planet-full-history/osm/${year}" "${year}"
178 install_dump "planet" "pbf" "<%= node[:planet][:dump][:pbf_directory] %>" "s3://osm-planet-eu-central-1/planet/pbf/${year}"
179 install_dump "history" "pbf" "<%= node[:planet][:dump][:pbf_history_directory] %>" "s3://osm-planet-eu-central-1/planet-full-history/pbf/${year}"