Mercurial > public > ssdt-docker
comparison scripts/remote-backup-all.sh @ 320:58c49a386a11
making changes to remote backup scripts to create directory
author | aldrich@ssdt-ohio.org |
---|---|
date | Thu, 31 Oct 2019 14:34:53 +0100 |
parents | 7c460a921709 |
children | 4285b8a2762e |
comparison
equal
deleted
inserted
replaced
319:7c460a921709 | 320:58c49a386a11 |
---|---|
27 container1=usasdb | 27 container1=usasdb |
28 container2=uspsdb | 28 container2=uspsdb |
29 | 29 |
30 project=$(composeGetProject) | 30 project=$(composeGetProject) |
31 | 31 |
32 #If the project is empty, we want to stop the process because this is being run from the wrong directory | |
33 | |
32 if [ "$project" == "" ]; then | 34 if [ "$project" == "" ]; then |
33 echo "no project available" | 35 echo "no project available" |
34 exit 1 | 36 exit 1 |
35 fi | 37 fi |
36 | 38 |
39 ## first will try to get IRNfrom usasdb; if that is empty it will try to get it from uspsdb | |
37 | 40 |
38 IRN=$(docker-compose exec -T $container1 psql --username=postgres --dbname=$container1 -t -c 'select irn from organization') | 41 IRN=$(docker-compose exec -T $container1 psql --username=postgres --dbname=$container1 -t -c 'select irn from organization') |
39 | 42 |
40 if [ "$IRN" == "" ]; then | 43 if [ "$IRN" == "" ]; then |
41 IRN=$(docker-compose exec -T $container2 psql --username=postgres --dbname=$container2 -t -c 'select irn from organization') | 44 IRN=$(docker-compose exec -T $container2 psql --username=postgres --dbname=$container2 -t -c 'select irn from organization') |
42 fi | 45 fi |
43 | 46 |
44 ##Trim function in postgres didn't work - so take out the extra space this way. | 47 ##Trim function in postgres didn't work - so take out the extra space this way. |
45 IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'` | 48 IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'` |
49 | |
50 ## if both database are empty, it will put IRN 000000 | |
51 if [ "$IRN" == "" ]; then | |
52 echo "no IRN set, using 000000" | |
53 IRN=000000 | |
54 fi | |
46 | 55 |
47 echo "project is $project" | 56 echo "project is $project" |
48 echo "Containers are $container1 and $container2" | 57 echo "Containers are $container1 and $container2" |
49 echo "Remote target is $remoteTarget" | 58 echo "Remote target is $remoteTarget" |
50 echo "Username is $userName" | 59 echo "Username is $userName" |
60 docker-compose exec -T $container1 sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container1 ; (exit $?) " > ${backupFile1} | 69 docker-compose exec -T $container1 sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container1 ; (exit $?) " > ${backupFile1} |
61 | 70 |
62 if [[ $( grep --count "CREATE TABLE" ${backupFile1} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile1} ) -eq 0 ]]; then | 71 if [[ $( grep --count "CREATE TABLE" ${backupFile1} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile1} ) -eq 0 ]]; then |
63 echo "ERROR: backup verification FAILED" | 72 echo "ERROR: backup verification FAILED" |
64 echo "ERROR: $(tail ${backupFile1})" | 73 echo "ERROR: $(tail ${backupFile1})" |
65 else | 74 echo "Error: empty database" |
75 #else We still gzip the backup file | |
66 gzip ${backupFile1} | 76 gzip ${backupFile1} |
67 | 77 |
68 echo "completed backup of $container1 for $project to ${backupFile1}" | 78 echo "completed backup of $container1 for $project to ${backupFile1}" |
69 | 79 |
70 fi | 80 fi |
77 docker-compose exec -T $container2 sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container2 ; (exit $?) " > ${backupFile2} | 87 docker-compose exec -T $container2 sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container2 ; (exit $?) " > ${backupFile2} |
78 | 88 |
79 if [[ $( grep --count "CREATE TABLE" ${backupFile2} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile2} ) -eq 0 ]]; then | 89 if [[ $( grep --count "CREATE TABLE" ${backupFile2} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile2} ) -eq 0 ]]; then |
80 echo "ERROR: backup verification FAILED" | 90 echo "ERROR: backup verification FAILED" |
81 echo "ERROR: $(tail ${backupFile2})" | 91 echo "ERROR: $(tail ${backupFile2})" |
82 else | 92 echo "Error: empty database" |
93 #else We still gzip the backup file | |
83 gzip ${backupFile2} | 94 gzip ${backupFile2} |
84 | 95 |
85 echo "completed backup of $container2 for $project to ${backupFile2}" | 96 echo "completed backup of $container2 for $project to ${backupFile2}" |
86 | 97 |
87 fi | 98 fi |