-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathrestore.sh
executable file
·63 lines (55 loc) · 2.23 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
set -o pipefail # trace ERR through pipes
set -o errtrace # trace ERR through 'time command' and other functions
set -o nounset ## set -u : exit the script if you try to use an uninitialised variable
set -o errexit ## set -e : exit the script if any statement returns a non-true return value
source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.config.sh"
if [ "$#" -ne 1 ]; then
echo "No type defined"
exit 1
fi
mkdir -p -- "${BACKUP_DIR}"
case "$1" in
###################################
## MySQL
###################################
"mysql")
if [[ -n "$(dockerContainerId mysql)" ]]; then
if [ -f "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" ]; then
logMsg "Starting MySQL restore..."
MYSQL_ROOT_PASSWORD=$(dockerExecMySQL printenv MYSQL_ROOT_PASSWORD)
bzcat "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}" | dockerExecMySQL sh -c "MYSQL_PWD=\"${MYSQL_ROOT_PASSWORD}\" mysql -h mysql -uroot"
echo "FLUSH PRIVILEGES;" | dockerExecMySQL sh -c "MYSQL_PWD=\"${MYSQL_ROOT_PASSWORD}\" mysql -h mysql -uroot"
logMsg "Finished"
else
errorMsg "MySQL backup file not found"
exit 1
fi
else
echo " * Skipping mysql restore, no such container"
fi
;;
###################################
## Solr
###################################
"solr")
if [[ -n "$(dockerContainerId solr)" ]]; then
if [ -f "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" ]; then
logMsg "Starting Solr restore..."
docker-compose stop solr
dockerExec rm -rf /storage/solr/
dockerExec mkdir -p /storage/solr/
dockerExec chmod 777 /storage/solr/
dockerCopyTo "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" "/tmp/solr-restore.tbz2"
dockerExec tar -jxPf "/tmp/solr-restore.tbz2" -C /
docker-compose start solr
logMsg "Finished"
else
errorMsg "Solr backup file not found"
exit 1
fi
else
echo " * Skipping solr restore, no such container"
fi
;;
esac