You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
628 B
Bash
30 lines
628 B
Bash
#!/bin/bash
|
|
#
|
|
#
|
|
#
|
|
|
|
STAGE=$1
|
|
DATABASE_SERVER=$2
|
|
|
|
DATADIR='/var/lib/postgresql/13/main'
|
|
DATE=$(date +%F)
|
|
|
|
PG_USER=postgres
|
|
PG_GROUP=postgres
|
|
|
|
systemctl stop postgresql
|
|
|
|
rm -rf ${DATADIR}
|
|
mkdir -p ${DATADIR}
|
|
|
|
LOCAL_BACKUP_DIR="/home/backupuser/backups/${STAGE}/postgres/${DATABASE_SERVER}"
|
|
BACKUP_FILE_ENCRYPTED=$(find "${LOCAL_BACKUP_DIR}/${DATE}/" -name *.gz.gpg | head -n 1)
|
|
|
|
# --batch => avoid error: >> gpg: cannot open '/dev/tty': No such device or address" <<
|
|
gpg --batch --decrypt $BACKUP_FILE_ENCRYPTED | tar -xz -C ${DATADIR}
|
|
|
|
chmod 0700 ${DATADIR}
|
|
chown -R ${PG_USER}:${PG_GROUP} ${DATADIR}
|
|
|
|
systemctl start postgresql
|