Mercurial > public > ssdt-docker
comparison scripts/remote-backup.sh @ 326:b35f4af06ed4 production vv2.6.0
flow: Merged <release> 'v2.6.0' to <master> ('production').
author | aldrich@ssdt-ohio.org |
---|---|
date | Tue, 12 Nov 2019 16:16:00 +0000 |
parents | 4285b8a2762e |
children |
comparison
equal
deleted
inserted
replaced
303:5d759b614c90 | 326:b35f4af06ed4 |
---|---|
25 set -o pipefail | 25 set -o pipefail |
26 mkdir -p ./backup | 26 mkdir -p ./backup |
27 | 27 |
28 project=$(composeGetProject) | 28 project=$(composeGetProject) |
29 | 29 |
30 #If the project is empty, we want to stop the process because this is being run from the wrong directory | |
31 if [ "$project" == "" ]; then | |
32 echo "no project available" | |
33 exit 1 | |
34 fi | |
35 | |
36 | |
37 IRN=$(docker-compose exec -T $container psql --username=postgres --dbname=$container -t -c 'select irn from organization') | |
38 ##Trim function in postgres didn't work - so take out the extra space this way. | |
39 IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'` | |
40 | |
41 ## if database is empty, it will put IRN 000000 | |
42 if [ "$IRN" == "" ]; then | |
43 echo "no IRN set, using 000000" | |
44 IRN=000000 | |
45 fi | |
46 | |
30 echo "Project is $project" | 47 echo "Project is $project" |
31 echo "Container is $container" | 48 echo "Container is $container" |
32 echo "Remote target is $remoteTarget" | 49 echo "Remote target is $remoteTarget" |
33 echo "Username is $userName" | 50 echo "Username is $userName" |
34 | 51 echo "IRN is $IRN" |
35 backupFile=./backup/${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup | |
36 backupFile2=./backup/${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).directorycontents.tar.gz | |
37 | 52 |
38 | 53 |
39 if [ "$project" == "" ]; then | 54 backupFile=./backup/${IRN}${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).backup |
40 echo "no project available" | 55 backupFile2=./backup/${IRN}${project}-${container}.$(date +%Y-%m-%d-%H-%M-%S).directorycontents.tar.gz |
41 exit 1 | 56 |
42 fi | 57 |
43 | 58 |
44 echo "starting backup of $container for $project" | 59 echo "starting backup of $container for $project" |
45 docker-compose exec -T $container sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container ; (exit $?) " > ${backupFile} | 60 docker-compose exec -T $container sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container ; (exit $?) " > ${backupFile} |
46 | 61 |
47 if [[ $( grep --count "CREATE TABLE" ${backupFile} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile} ) -eq 0 ]]; then | 62 if [[ $( grep --count "CREATE TABLE" ${backupFile} ) -lt 200 || $( grep --count "PostgreSQL database dump complete" ${backupFile} ) -eq 0 ]]; then |
48 echo "ERROR: backup verification FAILED" | 63 echo "ERROR: backup verification FAILED" |
64 echo "Error: empty database" | |
49 echo "ERROR: $(tail ${backupFile})" | 65 echo "ERROR: $(tail ${backupFile})" |
50 exit 1 | 66 # We want the process to continue even if the db is blank |
67 # exit 1 | |
51 fi | 68 fi |
52 | 69 |
53 gzip ${backupFile} | 70 gzip ${backupFile} |
54 | 71 |
55 echo "completed backup of $container for $project to ${backupFile}" | 72 echo "completed backup of $container for $project to ${backupFile}" |
56 | 73 |
57 #backup of all files in current directory | 74 #backup of all files in current directory |
58 tar -czf ${backupFile2} . --exclude=./backup | 75 #tar -czf ${backupFile2} . --exclude=./backup |
76 tar --exclude=./backup -czf ${backupFile2} . | |
59 | 77 |
60 echo "completed backup of all files for $project to ${backupFile2}" | 78 echo "completed backup of all files for $project to ${backupFile2}" |
61 | 79 |
80 #Create remote directory before scp | |
62 | 81 |
82 host=`echo $userName@$remoteTarget | sed -e 's/:.*//'` | |
83 | |
84 target=`echo $remoteTarget | sed -e 's/.*://'` | |
85 | |
86 ssh $host mkdir -p $target/$project | |
87 | |
88 #scp file | |
63 # | 89 # |
64 # | 90 scp ${backupFile}.gz ${backupFile2} $userName@$remoteTarget/$project |
65 scp ${backupFile}.gz ${backupFile2} $userName@$remoteTarget | |
66 | 91 |
67 echo " " | 92 echo " " |
68 | 93 |
69 echo "completed sending ${backupFile}.gz and ${backupFile2} to ${remoteTarget} as user $userName" | 94 echo "completed sending ${backupFile}.gz and ${backupFile2} to ${remoteTarget}/${project} as user $userName" |
70 | 95 |
71 | 96 |