|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 | set -e
|
3 |
| -export VOLUME_DIR=/mnt/data |
4 | 3 |
|
5 | 4 | # osmosis tuning: https://wiki.openstreetmap.org/wiki/Osmosis/Tuning,https://lists.openstreetmap.org/pipermail/talk/2012-October/064771.html
|
6 | 5 | if [ -z "$MEMORY_JAVACMD_OPTIONS" ]; then
|
7 |
| - echo JAVACMD_OPTIONS=\"-server\" >~/.osmosis |
| 6 | + echo JAVACMD_OPTIONS="-server" >~/.osmosis |
8 | 7 | else
|
9 | 8 | memory="${MEMORY_JAVACMD_OPTIONS//i/}"
|
10 |
| - echo JAVACMD_OPTIONS=\"-server -Xmx$memory\" >~/.osmosis |
| 9 | + echo JAVACMD_OPTIONS="-server -Xmx$memory" >~/.osmosis |
11 | 10 | fi
|
12 | 11 |
|
13 |
| -# Fixing name for historical file |
| 12 | +export VOLUME_DIR=/mnt/data |
| 13 | +export PLANET_EPOCH_DATE="${PLANET_EPOCH_DATE:-2004-01-01}" |
14 | 14 | date=$(date '+%y%m%d_%H%M')
|
15 |
| -local_fullHistoryFile=$VOLUME_DIR/history-${date}.osh.pbf |
16 |
| -cloud_fullHistoryFile=planet/full-history/history-${date}.osh.pbf |
17 | 15 |
|
18 |
| -# In case overwrite the file |
19 |
| -if [ "$OVERWRITE_FHISTORY_FILE" == "true" ]; then |
20 |
| - local_fullHistoryFile=$VOLUME_DIR/history-latest.osh.pbf |
21 |
| - cloud_fullHistoryFile=planet/full-history/history-latest.osh.pbf |
| 16 | +local_planetPBFFile=$VOLUME_DIR/planet-history-${date}.osm.pbf |
| 17 | +cloud_planetPBFFile=planet/planet-history-${date}.osm.pbf |
| 18 | +stateFile="$VOLUME_DIR/state.txt" |
| 19 | +dumpFile="$VOLUME_DIR/input-latest.dump" |
| 20 | + |
| 21 | + |
| 22 | +# If overwrite flag is enabled, use fixed filenames |
| 23 | +if [ "$OVERWRITE_PLANET_FILE" == "true" ]; then |
| 24 | + local_planetPBFFile=$VOLUME_DIR/planet-history-latest.osm.pbf |
| 25 | + cloud_planetPBFFile=planet/planet-history-latest.osm.pbf |
22 | 26 | fi
|
23 | 27 |
|
24 |
| -# State file nname |
25 |
| -stateFile="$VOLUME_DIR/state.txt" |
26 |
| -osm_tmp_file="osm_tmp.osm" |
| 28 | +# =============================== |
| 29 | +# Download db .dump file |
| 30 | +# =============================== |
| 31 | +download_dump_file() { |
| 32 | + echo "Downloading db .dump file from cloud..." |
| 33 | + if [ "$CLOUDPROVIDER" == "aws" ]; then |
| 34 | + if [[ "$DUMP_CLOUD_URL" == *.txt ]]; then |
| 35 | + temp_txt="$VOLUME_DIR/tmp_dump_url.txt" |
| 36 | + aws s3 cp "$DUMP_CLOUD_URL" "$temp_txt" |
| 37 | + first_line=$(head -n 1 "$temp_txt") |
| 38 | + aws s3 cp "$first_line" "$dumpFile" |
| 39 | + else |
| 40 | + aws s3 cp "$DUMP_CLOUD_URL" "$dumpFile" |
| 41 | + fi |
| 42 | + elif [ "$CLOUDPROVIDER" == "gcp" ]; then |
| 43 | + gsutil cp "$DUMP_CLOUD_URL" "$dumpFile" |
| 44 | + fi |
| 45 | +} |
27 | 46 |
|
28 |
| -# Creating full history |
29 |
| -osmosis --read-apidb-change \ |
30 |
| - host=$POSTGRES_HOST \ |
31 |
| - database=$POSTGRES_DB \ |
32 |
| - user=$POSTGRES_USER \ |
33 |
| - password=$POSTGRES_PASSWORD \ |
34 |
| - validateSchemaVersion=no \ |
35 |
| - readFullHistory=yes \ |
36 |
| - --write-xml-change \ |
37 |
| - compressionMethod=auto \ |
38 |
| - $osm_tmp_file |
| 47 | +# =============================== |
| 48 | +# Upload planet + state |
| 49 | +# =============================== |
| 50 | +upload_planet_file() { |
| 51 | + echo "Uploading history planet file and updating state.txt..." |
39 | 52 |
|
40 |
| -# Convert file to PBF file |
41 |
| -osmium cat $osm_tmp_file -o $local_fullHistoryFile |
42 |
| -osmium fileinfo $local_fullHistoryFile |
| 53 | + if [ "$CLOUDPROVIDER" == "aws" ]; then |
| 54 | + AWS_URL=${AWS_S3_BUCKET/s3:\/\//http:\/\/} |
| 55 | + echo "$AWS_URL.s3.amazonaws.com/$cloud_planetPBFFile" > "$stateFile" |
| 56 | + aws s3 cp "$local_planetPBFFile" "$AWS_S3_BUCKET/$cloud_planetPBFFile" --acl public-read |
| 57 | + aws s3 cp "$stateFile" "$AWS_S3_BUCKET/planet/state.txt" --acl public-read |
43 | 58 |
|
44 |
| -# Remove full-hitory osm file, keep only history-latest.osh.pbf files |
45 |
| -rm $osm_tmp_file |
| 59 | + elif [ "$CLOUDPROVIDER" == "gcp" ]; then |
| 60 | + echo "https://storage.cloud.google.com/$GCP_STORAGE_BUCKET/$cloud_planetPBFFile" > "$stateFile" |
| 61 | + gsutil cp -a public-read "$local_planetPBFFile" "$GCP_STORAGE_BUCKET/$cloud_planetPBFFile" |
| 62 | + gsutil cp -a public-read "$stateFile" "$GCP_STORAGE_BUCKET/planet/state.txt" |
| 63 | + fi |
| 64 | +} |
46 | 65 |
|
47 |
| -# AWS |
48 |
| -if [ $CLOUDPROVIDER == "aws" ]; then |
49 |
| - AWS_URL=${AWS_S3_BUCKET/s3:\/\//http:\/\/} |
50 |
| - echo "$AWS_URL.s3.amazonaws.com/$cloud_fullHistoryFile" >$stateFile |
51 |
| - # Upload history-planet.osm.pbf |
52 |
| - aws s3 cp $local_fullHistoryFile $AWS_S3_BUCKET/$cloud_fullHistoryFile --acl public-read |
53 |
| - # Upload state.txt |
54 |
| - aws s3 cp $stateFile $AWS_S3_BUCKET/planet/full-history/state.txt --acl public-read |
55 |
| -fi |
| 66 | +# =============================== |
| 67 | +# Generate planet file |
| 68 | +# =============================== |
56 | 69 |
|
57 |
| -# Google Storage |
58 |
| -if [ $CLOUDPROVIDER == "gcp" ]; then |
59 |
| - echo "https://storage.cloud.google.com/$GCP_STORAGE_BUCKET/$cloud_fullHistoryFile" >$stateFile |
60 |
| - # Upload history-planet.osm.pbf |
61 |
| - gsutil cp -a public-read $local_fullHistoryFile $GCP_STORAGE_BUCKET/$cloud_fullHistoryFile |
62 |
| - # Upload state.txt |
63 |
| - gsutil cp -a public-read $stateFile $GCP_STORAGE_BUCKET/planet/full-history/state.txt |
64 |
| -fi |
| 70 | +if [ "$PLANET_EXPORT_METHOD" == "planet-dump-ng" ]; then |
| 71 | + download_dump_file |
| 72 | + echo "Generating history planet file with planet-dump-ng..." |
| 73 | + export PLANET_EPOCH_DATE="$PLANET_EPOCH_DATE" |
| 74 | + planet-dump-ng \ |
| 75 | + --dump-file "$dumpFile" \ |
| 76 | + --history-pbf "$local_planetPBFFile" |
65 | 77 |
|
66 |
| -# Azure |
67 |
| -if [ $CLOUDPROVIDER == "azure" ]; then |
68 |
| - # Save the path file |
69 |
| - echo "https://$AZURE_STORAGE_ACCOUNT.blob.core.windows.net/$AZURE_CONTAINER_NAME/$cloud_fullHistoryFile" >$stateFile |
70 |
| - # Upload history-planet.osm.pbf |
71 |
| - az storage blob upload \ |
72 |
| - --container-name $AZURE_CONTAINER_NAME \ |
73 |
| - --file $local_fullHistoryFile \ |
74 |
| - --name $cloud_fullHistoryFile \ |
75 |
| - --output table |
76 |
| - # Upload state.txt |
77 |
| - az storage blob upload \ |
78 |
| - --container-name $AZURE_CONTAINER_NAME \ |
79 |
| - --file $stateFile \ |
80 |
| - --name planet/full-history/state.txt \ |
81 |
| - --output table |
| 78 | +elif [ "$PLANET_EXPORT_METHOD" == "osmosis" ]; then |
| 79 | + echo "Generating history planet file with osmosis..." |
| 80 | + # Creating full history |
| 81 | + osmosis --read-apidb-change \ |
| 82 | + host=$POSTGRES_HOST \ |
| 83 | + database=$POSTGRES_DB \ |
| 84 | + user=$POSTGRES_USER \ |
| 85 | + password=$POSTGRES_PASSWORD \ |
| 86 | + validateSchemaVersion=no \ |
| 87 | + readFullHistory=yes \ |
| 88 | + --write-xml-change \ |
| 89 | + compressionMethod=auto \ |
| 90 | + $local_planetPBFFile |
| 91 | +else |
| 92 | + echo "Error: Unknown PLANET_EXPORT_METHOD value. Use 'planet-dump-ng' or 'osmosis'." |
| 93 | + exit 1 |
82 | 94 | fi
|
| 95 | + |
| 96 | +# Upload results |
| 97 | +upload_planet_file |
0 commit comments