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.
hetzner-ansible/roles/restore_maria/files/restore.sh

30 lines
658 B
Bash

#!/bin/bash
#
#
#
#
STAGE=$1
DATABASE_SERVER=$2
DATADIR='/var/lib/mysql'
DATE=$(date +%F)
systemctl stop mariadb
rm -rf ${DATADIR}_moved
mv ${DATADIR} ${DATADIR}_moved
mkdir -p ${DATADIR}
LOCAL_BACKUP_DIR="/home/backupuser/backups/${STAGE}/maria/${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 | gunzip | mbstream --directory ${DATADIR} -x --parallel=2
mariabackup --prepare --target-dir=${DATADIR}
chown -R mysql:mysql ${DATADIR}
systemctl start mariadb