9b6659a85a
- backup-app.sh: pg_dump 16 (--exclude planet_osm_*), .env+compose в tar, verify через pg_restore --list, чистка >14 дней - restore-app.sh: pg_restore 16 --clean --if-exists + TOC без EXTENSION - ГРАБЛИ pg_wrapper PG18 в контейнере postgres:16: архив версии 1.16 не читается pg_restore 16 (unsupported version) + SET transaction_timeout нет в PG16 — только /usr/lib/postgresql/16/bin/pg_*
37 lines
1.7 KiB
Bash
37 lines
1.7 KiB
Bash
#!/bin/bash
|
|
# B23: восстановление прикладного дампа ВЕКТОРа в живую БД.
|
|
#
|
|
# Грабли (реальный прогон 2026-09):
|
|
# 1. pg_dump/pg_restore в контейнере postgres:16 — pg_wrapper ведёт на клиент PG18:
|
|
# pg_restore 18 создаёт архив версии 1.16, который pg_restore 16 НЕ читает
|
|
# ("unsupported version"), и пишет "SET transaction_timeout", отсутствующий
|
|
# в PG16-сервере. Лечение: ТОЛЬКО /usr/lib/postgresql/16/bin/pg_*.
|
|
# 2. --clean дропает postgis → падение на зависимостях planet_osm_*.
|
|
# EXTENSION-строки фильтруются из TOC (postgis стоит, OSM-данных в дампе нет).
|
|
# Использование: restore-app.sh /root/backups/vector_app_2026-09-25.dump
|
|
set -eu
|
|
LOG=/var/log/vector-restore.log
|
|
PG16=/usr/lib/postgresql/16/bin
|
|
log() { echo "[$(date '+%F %T')] $*" >> "$LOG"; }
|
|
|
|
if [ $# -lt 1 ] || [ ! -f "$1" ]; then
|
|
echo "usage: restore-app.sh <dump-file>" >&2
|
|
exit 1
|
|
fi
|
|
log "restore start from $1"
|
|
|
|
docker cp "$1" vector-postgres:/tmp/restore.dump
|
|
|
|
# TOC без EXTENSION postgis (уже установлен; дамп OSM-таблиц не содержит)
|
|
docker exec vector-postgres "$PG16/pg_restore" --list /tmp/restore.dump | grep -v EXTENSION > /tmp/restore.toc
|
|
|
|
if docker exec vector-postgres "$PG16/pg_restore" -U postgres -d vector_mchs \
|
|
--clean --if-exists --no-owner --use-list=/tmp/restore.toc /tmp/restore.dump; then
|
|
log "restore ok"
|
|
else
|
|
log "RESTORE FAILED"
|
|
exit 1
|
|
fi
|
|
|
|
docker exec vector-postgres rm -f /tmp/restore.dump /tmp/restore.toc
|
|
log "done" |