-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore.sh
executable file
·31 lines (27 loc) · 1018 Bytes
/
restore.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
set -e
#export MC_HOST_backup=$S3_URI
#mc mb backup/${S3_BUCKET} --insecure
REGEX="^([a-zA-Z0-9\._=-]+):\/\/([a-zA-Z0-9\/\._=-]+):([a-zA-Z0-9\._=-]+)@([a-zA-Z0-9\.-]+):?([0-9]*)\/([a-zA-Z0-9\/\._=-]+)$"
if [[ "$DATABASE_URL" =~ $REGEX ]]; then
export DATABASE_ADAPTER="${BASH_REMATCH[1]:-mysql2}"
export DATABASE_USER="${BASH_REMATCH[2]}"
export DATABASE_PASSWORD="${BASH_REMATCH[3]}"
export DATABASE_HOST="${BASH_REMATCH[4]:-localhost}"
export DATABASE_PORT="${BASH_REMATCH[5]:-3306}"
export DATABASE_NAME="${BASH_REMATCH[6]}"
fi
mc find backup/${S3_BUCKET}/ --name "${BACKUP_NAME_PREFIX}*.sql.gz.enc" \
| tail -n 1 \
| xargs mc cat \
| openssl enc -aes-256-cbc -salt -d -pass pass:$CRYPT_PASSPHRASE \
| gunzip -9 > backup.sql
read -p "Press any key to continue... " -n1 -s
cat backup.sql \
| mysql -h ${DATABASE_HOST} \
-P ${DATABASE_PORT} \
-u ${DATABASE_USER} \
--password=${DATABASE_PASSWORD} \
--skip-add-locks \
--allow-keywords \
${DATABASE_NAME}