Restoring Zammad from backup: Workaround for missing DROP TABLE IF EXISTS statement in DB dumps created with an older pgdump version.

This commit is contained in:
Marcel Herrguth 2020-04-24 09:47:25 +02:00 committed by Thorsten Eckel
parent 62a6d5e2ca
commit 57f40539f2

View file

@ -159,6 +159,26 @@ function restore_zammad () {
chown -R zammad:zammad ${ZAMMAD_DIR} chown -R zammad:zammad ${ZAMMAD_DIR}
if [ "${DB_ADAPTER}" == "postgresql" ]; then if [ "${DB_ADAPTER}" == "postgresql" ]; then
echo "# ... Dropping current database ${DB_NAME}"
# This step is only needed for some pgsql dumps, as they don't provide a drop table statement which will cause
# relation errors during restoration (as on package installation there's always an initialised database)
if command -v zammad > /dev/null; then
zammad config:set DISABLE_DATABASE_ENVIRONMENT_CHECK=1
zammad run rake db:drop
zammad config:set DISABLE_DATABASE_ENVIRONMENT_CHECK=0
else
${ZAMMAD_DIR}/bin/rake db:drop
fi
echo "# ... Creating database ${DB_NAME} for owner ${DB_USER}"
if command -v zammad > /dev/null; then
# We'll skip this part for docker installations
su -c "psql -c \"CREATE DATABASE ${DB_NAME} OWNER ${DB_USER};\"" postgres
else
${ZAMMAD_DIR}/bin/rake db:create
fi
echo "# Restoring PostgrSQL DB" echo "# Restoring PostgrSQL DB"
zcat ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz | su -c "psql -d ${DB_NAME}" postgres zcat ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz | su -c "psql -d ${DB_NAME}" postgres
elif [ "${DB_ADAPTER}" == "mysql2" ]; then elif [ "${DB_ADAPTER}" == "mysql2" ]; then