-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathbackup.sh
executable file
·57 lines (48 loc) · 1.99 KB
/
backup.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
#!/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 "Removing old backup file..."
rm -f -- "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}"
fi
logMsg "Starting MySQL backup..."
MYSQL_ROOT_PASSWORD=$(dockerExecMySQL printenv MYSQL_ROOT_PASSWORD)
dockerExecMySQL sh -c "MYSQL_PWD=\"${MYSQL_ROOT_PASSWORD}\" mysqldump -h mysql -uroot --opt --single-transaction --events --all-databases --routines --comments" | bzip2 > "${BACKUP_DIR}/${BACKUP_MYSQL_FILE}"
logMsg "Finished"
else
echo " * Skipping mysql backup, no such container"
fi
;;
###################################
## Solr
###################################
"solr")
if [[ -n "$(dockerContainerId solr)" ]]; then
logMsg "Starting Solr backup..."
docker-compose stop solr
if [ -f "${BACKUP_DIR}/${BACKUP_SOLR_FILE}" ]; then
logMsg "Removing old backup file..."
rm -f -- "${BACKUP_DIR}/${BACKUP_SOLR_FILE}"
fi
dockerExec tar -cP --to-stdout /storage/solr/ | bzip2 > "${BACKUP_DIR}/${BACKUP_SOLR_FILE}"
docker-compose start solr
logMsg "Finished"
else
echo " * Skipping solr backup, no such container"
fi
;;
esac