Vereinfache ERP-Backup auf direkten PostgreSQL-Container
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
services:
|
||||
backup:
|
||||
image: postgres:17.7-alpine
|
||||
network_mode: host
|
||||
environment:
|
||||
PGHOST: ${DB_HOST}
|
||||
PGPORT: ${DB_PORT}
|
||||
PGDATABASE: ${DB_NAME}
|
||||
PGUSER: ${DB_USER}
|
||||
PGPASSWORD: ${DB_PASSWORD}
|
||||
entrypoint: ["pg_dump"]
|
||||
command:
|
||||
- "--format=custom"
|
||||
- "--no-owner"
|
||||
- "--no-privileges"
|
||||
- "--file=/backup/current.dump"
|
||||
volumes:
|
||||
- /volume1/naurua_db_backups/dev:/backup
|
||||
@@ -7,10 +7,7 @@ ROOT_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd)"
|
||||
ENV_FILE="${ROOT_DIR}/.env"
|
||||
BACKUP_DIR="${BACKUP_DIR:-/volume1/naurua_db_backups/dev}"
|
||||
FILE_PREFIX="${FILE_PREFIX:-erpnaurua_dev}"
|
||||
PG_DUMP_BIN="${PG_DUMP_BIN:-$(command -v pg_dump || true)}"
|
||||
PSQL_BIN="${PSQL_BIN:-$(command -v psql || true)}"
|
||||
DOCKER_BIN="${DOCKER_BIN:-$(command -v docker || true)}"
|
||||
COMPOSE_FILE="${COMPOSE_FILE:-${ROOT_DIR}/scripts/db/backup-client/docker-compose.yml}"
|
||||
DOCKER_CMD=()
|
||||
|
||||
if [[ ! -f "${ENV_FILE}" ]]; then
|
||||
@@ -34,11 +31,6 @@ if [[ -z "${DOCKER_BIN}" || ! -x "${DOCKER_BIN}" ]]; then
|
||||
echo "Docker is required for the PostgreSQL client container." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -f "${COMPOSE_FILE}" ]]; then
|
||||
echo "Missing backup compose file: ${COMPOSE_FILE}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if "${DOCKER_BIN}" info >/dev/null 2>&1; then
|
||||
DOCKER_CMD=("${DOCKER_BIN}")
|
||||
elif sudo -n "${DOCKER_BIN}" info >/dev/null 2>&1; then
|
||||
@@ -57,7 +49,16 @@ cleanup() { rm -f "${temporary_file}"; }
|
||||
trap cleanup EXIT
|
||||
|
||||
export BACKUP_DIR
|
||||
"${DOCKER_CMD[@]}" compose --env-file "${ENV_FILE}" --file "${COMPOSE_FILE}" run --rm --no-deps -T backup
|
||||
"${DOCKER_CMD[@]}" run --rm --network host \
|
||||
--env-file "${ENV_FILE}" \
|
||||
-e "PGHOST=${DB_HOST}" \
|
||||
-e "PGPORT=${DB_PORT}" \
|
||||
-e "PGDATABASE=${DB_NAME}" \
|
||||
-e "PGUSER=${DB_USER}" \
|
||||
-e "PGPASSWORD=${DB_PASSWORD}" \
|
||||
-v "${BACKUP_DIR}:/backup" \
|
||||
postgres:17.7-alpine \
|
||||
pg_dump --format=custom --no-owner --no-privileges --file=/backup/current.dump
|
||||
|
||||
if [[ ! -s "${BACKUP_DIR}/current.dump" ]]; then
|
||||
echo "Backup failed: container dump file is empty." >&2
|
||||
|
||||
Reference in New Issue
Block a user