3
0
Fork 0
medicine-config/medicine/backup-light.sh

58 lines
2.0 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# Лайт-бэкап medicine для cloud:
# medicine-for-cloud-base.tar.gz — основа без тяжёлых данных
#
# Исключены данные:
# booking_*, registry_*,
# record_group, record_hospitaltransferdepartment, record_preferentialcategory,
# record_record, record_recordservice, record_signeddocument
# (+ прочие тяжёлые/технические таблицы)
#
# record_case* остаются в основном дампе.
#
# Restore:
# tar -xzf medicine-for-cloud-base.tar.gz
# psql -U postgres -d medicine -f medicine-for-cloud-base.sql
set -e
export LC_ALL=C
CONTAINER="${POSTGRES_CONTAINER:-medicine-stack-postgres}"
DB_USER="${POSTGRES_USER:-postgres}"
DB_NAME="${POSTGRES_DB:-medicine}"
BACKUP_DIR="${BACKUP_DIR:-${HOME}/medicine-backups}"
mkdir -p "${BACKUP_DIR}"
cd "${BACKUP_DIR}"
base_sql="medicine-for-cloud-base.sql"
base_archive="medicine-for-cloud-base.tar.gz"
echo "==> base dump: ${base_sql}"
docker exec -i "${CONTAINER}" pg_dump --no-owner -U "${DB_USER}" -F p "${DB_NAME}" \
--exclude-table-data=riisz_logging \
--exclude-table-data=patient_changes \
--exclude-table-data=всеалоны_подробно \
--exclude-table-data=талоны_подробно \
--exclude-table-data=всеалоны \
--exclude-table-data=пациенты \
--exclude-table-data='historical_*' \
--exclude-table-data='local_*' \
--exclude-table-data='reversion_*' \
--exclude-table-data='booking_*' \
--exclude-table-data='registry_*' \
--exclude-table-data=record_group \
--exclude-table-data=record_hospitaltransferdepartment \
--exclude-table-data=record_preferentialcategory \
--exclude-table-data=record_record \
--exclude-table-data=record_recordservice \
--exclude-table-data=record_signeddocument \
> "${base_sql}"
echo "==> archive: ${base_archive}"
rm -f "${base_archive}"
tar -czf "${base_archive}" "${base_sql}"
rm -f "${base_sql}"
echo "Done: ${BACKUP_DIR}/${base_archive}"