Mercurial > public > ssdt-docker
comparison scripts/restore-container.sh @ 229:6210629ba54f production v1.7.0
flow: Merged <release> 'v1.7.0' to <master> ('production').
author | smith@nwoca.org |
---|---|
date | Mon, 09 Oct 2017 21:35:35 +0100 |
parents | 2e0d3c70bba2 |
children | 5be78ce3b33c |
comparison
equal
deleted
inserted
replaced
224:fe6e83ff2d12 | 229:6210629ba54f |
---|---|
1 #!/bin/bash | |
2 | |
3 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh" | |
4 | |
5 sourceFile=${1?must provide backup file to be restored} | |
6 | |
7 if [ -z "$1" ] | |
8 then | |
9 echo "Usage: `basename $0` {backup file to restore}" | |
10 echo " must specify the name of the file to restore. Assumed to be in format:" | |
11 echo " {service}.{timestamp}.backup.gz " | |
12 echo " where {service} is the usasdb or uspsdb container to be restored." | |
13 echo " The script will restore the backup to the appropriate container based " | |
14 echo " on the filename." | |
15 exit $E_NOARGS | |
16 fi | |
17 | |
18 target=$(basename $1) | |
19 target=${target%%.*} | |
20 | |
21 project=$(composeGetProject $target) | |
22 | |
23 if [ "$project" == "" ]; then | |
24 echo "no project available" | |
25 exit 1 | |
26 fi | |
27 | |
28 echo | |
29 echo "Preparing to restore" | |
30 echo "--------------------" | |
31 echo " file: $sourceFile" | |
32 echo " to ${project}/${target} database: $target" | |
33 echo " " | |
34 echo "WARNING: This operation will DELETE and replace any exising database" | |
35 echo " " | |
36 | |
37 read -e -p "Continue? <y/N> " answer | |
38 case $answer in | |
39 y | Y | yes | YES ) answer="y";; | |
40 n | N | no | NO ) answer="n";; | |
41 *) answer="n" | |
42 esac | |
43 | |
44 if [ "$answer" == "y" ] | |
45 then | |
46 appService=${target/db/app} | |
47 echo "stopping application service $appService" | |
48 docker-compose stop $appService | |
49 | |
50 dbContainer=$(composeGetContainer $target) | |
51 | |
52 echo "copy backup file to database container" | |
53 docker cp ${sourceFile} ${dbContainer}:/tmp/restore.backup.gz | |
54 | |
55 echo "starting database restore" | |
56 docker-compose exec -T -u postgres $target sh -c "gunzip -f /tmp/restore.backup.gz -c | psql" | |
57 | |
58 fi | |
59 |