From 2781bbe21332acf03b135190b7e77a40d5e75ac4 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 24 Jul 2026 19:35:26 +0100 Subject: [PATCH] Switch planet dump to generate it's own database dumps --- cookbooks/db/recipes/master.rb | 13 ++++- cookbooks/planet/recipes/dump.rb | 47 ++++++++++++------- .../templates/default/planetdump-trigger.erb | 4 -- .../planet/templates/default/planetdump.erb | 36 +++++++++----- 4 files changed, 67 insertions(+), 33 deletions(-) delete mode 100644 cookbooks/planet/templates/default/planetdump-trigger.erb diff --git a/cookbooks/db/recipes/master.rb b/cookbooks/db/recipes/master.rb index 10d589aa3..aa9ff643f 100644 --- a/cookbooks/db/recipes/master.rb +++ b/cookbooks/db/recipes/master.rb @@ -118,9 +118,20 @@ CGIMAP_PERMISSIONS = { }.freeze PLANETDUMP_PERMISSIONS = { + "changeset_comments" => :select, + "changeset_tags" => :select, + "changesets" => :select, + "node_tags" => :select, + "nodes" => :select, "note_comments" => :select, "notes" => :select, - "users" => :select + "relation_members" => :select, + "relation_tags" => :select, + "relations" => :select, + "users" => :select, + "way_nodes" => :select, + "way_tags" => :select, + "ways" => :select }.freeze PLANETDIFF_PERMISSIONS = { diff --git a/cookbooks/planet/recipes/dump.rb b/cookbooks/planet/recipes/dump.rb index a18f090cf..6ade68566 100644 --- a/cookbooks/planet/recipes/dump.rb +++ b/cookbooks/planet/recipes/dump.rb @@ -20,6 +20,8 @@ include_recipe "git" include_recipe "planet::user" +db_passwords = data_bag_item("db", "passwords") + package %w[ gcc g++ @@ -93,19 +95,22 @@ directory "/store/planetdump" do recursive true end -%w[planetdump planetdump-trigger].each do |program| - template "/usr/local/bin/#{program}" do - source "#{program}.erb" - owner "root" - group "root" - mode "755" - end +template "/usr/local/bin/planetdump" do + source "planetdump.erb" + owner "root" + group "root" + mode "755" + variables :password => db_passwords["planetdump"] end systemd_service "planetdump@" do - description "Planet dump for %i" + action :delete +end + +systemd_service "planetdump" do + description "Planet dump" user "planet" - exec_start "/usr/local/bin/planetdump %i" + exec_start "/usr/local/bin/planetdump" memory_max "64G" sandbox :enable_network => true protect_home "tmpfs" @@ -119,15 +124,23 @@ systemd_service "planetdump@" do ] end -systemd_service "planetdump-trigger" do - description "Planet dump trigger" - user "root" - exec_start "/usr/local/bin/planetdump-trigger" - sandbox true - restrict_address_families "AF_UNIX" +systemd_timer "planetdump" do + description "Planet dump" + on_calendar "Mon 02:00 #{node[:timezone]}" end -service "planetdump-trigger" do +service "planetdump.timer" do action [:enable, :start] - subscribes :restart, "template[/usr/local/bin/planetdump-trigger]" +end + +service "planetdump-trigger" do + action [:disable, :stop] +end + +systemd_service "planetdump-trigger" do + action :delete +end + +file "/usr/local/bin/planetdump-trigger" do + action :delete end diff --git a/cookbooks/planet/templates/default/planetdump-trigger.erb b/cookbooks/planet/templates/default/planetdump-trigger.erb deleted file mode 100644 index b24197f4d..000000000 --- a/cookbooks/planet/templates/default/planetdump-trigger.erb +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -inotifywait --quiet --monitor --event CREATE --event MOVED_TO --include "/osm-[0-9]{4}-[0-9]{2}-[0-9]{2}\\.dmp\$" --format %f /store/backup | \ - xargs -I %file% systemctl start planetdump@%file%.service diff --git a/cookbooks/planet/templates/default/planetdump.erb b/cookbooks/planet/templates/default/planetdump.erb index 5c0d38045..41e6b4314 100644 --- a/cookbooks/planet/templates/default/planetdump.erb +++ b/cookbooks/planet/templates/default/planetdump.erb @@ -5,16 +5,9 @@ # Exit on error set -e -# Get the name of the file and the expected pattern -file="$1" -pattern="^osm-([0-9]{4})-([0-9]{2})-([0-9]{2})\.dmp$" - -# Give up now if the file isn't a database dump -[[ $file =~ $pattern ]] || exit 0 - -# Save the year and date from the file name -year="${BASH_REMATCH[1]}" -date="${year:2:2}${BASH_REMATCH[2]}${BASH_REMATCH[3]}" +# Save the year and date +year=$(date +%Y) +date=$(date +%y%m%d) # Check the lock if [ -f /tmp/planetdump.lock ]; then @@ -42,16 +35,37 @@ trap cleanup EXIT cd /store/planetdump # Cleanup +rm -rf osm.dmp rm -rf users rm -rf changesets changeset_tags changeset_comments rm -rf nodes node_tags rm -rf ways way_tags way_nodes rm -rf relations relation_tags relation_members +# Dun the database dump +PGPASSWORD="<%= @password %>" \ + pg_dump --host=<%= node[:web][:database_host] %> \ + --user=planetdump \ + --format=custom \ + --data-only \ + --table=users \ + --table=changesets \ + --table=changeset_tags \ + --table=changeset_comments \ + --table=nodes \ + --table=node_tags \ + --table=relations \ + --table=relation_tags \ + --table=relation_members \ + --table=ways \ + --table=way_tags \ + --table=way_nodes \ + --file=/store/planetdump/osm.dmp openstreetmap + # Run the dump time nice -n 19 /opt/planet-dump-ng/planet-dump-ng \ --max-concurrency=4 \ - -c "pbzip2 -c" -f "/store/backup/${file}" --dense-nodes=1 \ + -c "pbzip2 -c" -f "/store/planetdump/osm.dmp" --dense-nodes=1 \ -C "changesets-${date}.osm.bz2" \ -D "discussions-${date}.osm.bz2" \ -x "planet-${date}.osm.bz2" -X "history-${date}.osm.bz2" \ -- 2.47.3