comparison scripts/remote-backup-all.sh @ 314:d78b45c28205

backup script adding IRN to name
author aldrich@ssdt-ohio.org
date Mon, 28 Oct 2019 19:43:53 +0100
parents 4cc087cde1d0
children 146c0c263cf9
comparison
equal deleted inserted replaced
313:06e92ad77e7f 314:d78b45c28205
10 # 10 #
11 # 11 #
12 # This will backup both usasdb and uspsdb, 12 # This will backup both usasdb and uspsdb,
13 # along with the top level contents of the project directory 13 # along with the top level contents of the project directory
14 #Environment variables can be used for REMOTE_BACKUP_TARGET and REMOTE_USERNAME 14 #Environment variables can be used for REMOTE_BACKUP_TARGET and REMOTE_USERNAME
15
16 remoteTarget=${1:-$REMOTE_BACKUP_TARGET} 15 remoteTarget=${1:-$REMOTE_BACKUP_TARGET}
17 userName=${2:-$REMOTE_USERNAME} 16 userName=${2:-$REMOTE_USERNAME}
18 projectDir=${3:-$PWD} 17 projectDir=${3:-$PWD}
19 18
20 19
28 container1=usasdb 27 container1=usasdb
29 container2=uspsdb 28 container2=uspsdb
30 29
31 project=$(composeGetProject) 30 project=$(composeGetProject)
32 31
33 echo "project is $project"
34 echo "Containers are $container1 and $container2"
35 echo "Remote target is $remoteTarget"
36 echo "Username is $userName"
37
38 if [ "$project" == "" ]; then 32 if [ "$project" == "" ]; then
39 echo "no project available" 33 echo "no project available"
40 exit 1 34 exit 1
41 fi 35 fi
42 36
43 37
44 backupFile1=./backup/${project}-${container1}.$(date +%Y-%m-%d-%H-%M-%S).backup 38 IRN=$(docker-compose exec -T $container1 psql --username=postgres --dbname=$container1 -t -c 'select irn from organization')
45 backupFile2=./backup/${project}-${container2}.$(date +%Y-%m-%d-%H-%M-%S).backup 39
46 backupFile3=./backup/${project}-directory.$(date +%Y-%m-%d-%H-%M-%S).directorycontents.tar.gz 40 if ["$IRN" == ""]; then
41 IRN=$(docker-compose exec -T $container2 psql --username=postgres --dbname=$container2 -t -c 'select irn from organization')
42 fi
43
44 ##Trim function in postgres didn't work - so take out the extra space this way.
45 IRN=`echo $IRN | sed -e 's/^[[:space:]]*//'`
46
47 echo "project is $project"
48 echo "Containers are $container1 and $container2"
49 echo "Remote target is $remoteTarget"
50 echo "Username is $userName"
51 echo "IRN is $IRN"
52
53
54 backupFile1=./backup/${IRN}${project}-${container1}.$(date +%Y-%m-%d-%H-%M-%S).backup
55 backupFile2=./backup/${IRN}${project}-${container2}.$(date +%Y-%m-%d-%H-%M-%S).backup
56 backupFile3=./backup/${IRN}${project}-directory.$(date +%Y-%m-%d-%H-%M-%S).directorycontents.tar.gz
47 57
48 #usasdb 58 #usasdb
49 echo "starting backup of $container1 for $project" 59 echo "starting backup of $container1 for $project"
50 docker-compose exec -T $container1 sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container1 ; (exit $?) " > ${backupFile1} 60 docker-compose exec -T $container1 sh -c "gosu postgres pg_dump -Cc --if-exists --dbname=$container1 ; (exit $?) " > ${backupFile1}
51 61
79 ####### 89 #######
80 90
81 #backup of all files in current directory 91 #backup of all files in current directory
82 echo "starting backup of current directory for $project" 92 echo "starting backup of current directory for $project"
83 93
84 tar -czf ${backupFile3} . --exclude=./backup 94 #tar -czf ${backupFile3} . --exclude=./backup
95 tar --exclude=./backup -czf ${backupFile3} . --exclude=./backup
85 96
86 echo "completed backup of all files for $project to ${backupFile3}" 97 echo "completed backup of all files for $project to ${backupFile3}"
87 98
88 99
89 # 100 #