Last active
April 9, 2020 14:37
-
-
Save mingalevme/f8ae013d2895801fa372feb5339e251e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
PROJECT_CODE_NAME=${PROJECT_CODE_NAME:?} | |
PG_VERSION_FROM=${PG_VERSION_FROM:?} | |
PG_VERSION_TO=${PG_VERSION_TO:?} | |
ILLUMINATE_PROJECT_USERNAME="${ILLUMINATE_PROJECT_USERNAME:-$PROJECT_CODE_NAME}" | |
PGHOST=${PGHOST:-127.0.0.1} | |
PGPORT=${PGPORT:-5432} | |
PGUSER="${PGUSER:-$PROJECT_CODE_NAME}" | |
PGPASSWORD="${PGPASSWORD:-$PROJECT_CODE_NAME}" | |
PGDATABASE="${PGDATABASE:-$PROJECT_CODE_NAME}" | |
su - "${ILLUMINATE_PROJECT_USERNAME}" -c "php artisan --env deploying down --message='Upgrading Database' --retry=60" | |
systemctl stop supervisor | |
systemctl stop php-fpm | |
systemctl stop nginx | |
systemctl stop crond | |
BACKUP_FILENAME=/var/lib/pgsql/${PG_VERSION_FROM}/backups/${PGDATABASE}-$(date +"%Y-%m-%dT%H-%M-%S%z").sql | |
PGPASSWORD="${PGPASSWORD}" psql -h ${PGHOST} -p ${PGPORT} -U "${PGUSER}" "${PGDATABASE}" > "${BACKUP_FILENAME}" | |
echo "Backed up to: ${BACKUP_FILENAME}" | |
systemctl stop "postgresql-${PG_VERSION_FROM}" | |
systemctl disable "postgresql-${PG_VERSION_FROM}" | |
systemctl start "postgresql-${PG_VERSION_TO}" | |
PGPASSWORD="${PGPASSWORD}" psql -h ${PGHOST} -p ${PGPORT} -U "${PGUSER}" "${PGDATABASE}" < "${BACKUP_FILENAME}" | |
systemctl enable "postgresql-${PG_VERSION_TO}" | |
systemctl start crond | |
systemctl start nginx | |
systemctl start php-fpm | |
systemctl start supervisor | |
su - "${ILLUMINATE_PROJECT_USERNAME}" -c "php artisan --env deploying up" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment