-
Notifications
You must be signed in to change notification settings - Fork 2
/
restore.sh
executable file
·40 lines (25 loc) · 910 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
32
33
34
35
36
37
38
#!/bin/bash
set -e
set -x
docker_compose_file=docker-compose.prod.yml
results_dir=results/
backup_dir=${1}
function _clean_db() {
docker-compose -f ${docker_compose_file} stop postgres
docker-compose -f ${docker_compose_file} rm -f postgres
docker-compose -f ${docker_compose_file} up -d postgres
until docker-compose -f ${docker_compose_file} exec postgres pg_isready ; do sleep 1 ; done
}
source .env
usage="${0} <backup_path>"
if [ -z "$1" ]; then
echo "usage: $usage"
exit 0
fi
# restore exports
mkdir -p ${results_dir}
cp ${backup_dir}/${results_dir}/* ${results_dir} -r
# restore postgres
_clean_db
cat ${backup_dir}/postgres_backup.sql.gz | gunzip | docker-compose -f ${docker_compose_file} exec -T postgres psql -U $POSTGRES_USER
cat ${backup_dir}/redis_backup.rdb.gz | gunzip | docker-compose -f ${docker_compose_file} exec -T redis bash -ic 'dd of=/data/dump.rdb'