329
|
1 #!/bin/bash
|
|
2 # This is similar to the remote backup script except it uses an existing database backup
|
|
3 # MCOECN personnel used the basic script and modified it
|
|
4 # The current directory is expected to contain a project configured
|
|
5 # as with SSDT conventions for an application database.
|
|
6 #
|
|
7 # The file will also be placed on the specified remote target
|
|
8 # The format of the output is a compressed pg_dump (sql) format.
|
|
9 #
|
|
10 #
|
|
11 # This will send both usasdb and uspsdb,
|
|
12 # along with the top level contents of the project directory
|
|
13 #Environment variables can be used for REMOTE_BACKUP_TARGET and REMOTE_USERNAME
|
|
14 remoteTarget=${1:-$REMOTE_BACKUP_TARGET}
|
|
15 userName=${2:-$REMOTE_USERNAME}
|
|
16 projectDir=${3:-$PWD}
|
|
17
|
|
18 cd $projectDir
|
|
19
|
|
20 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh"
|
|
21
|
|
22 set -o pipefail
|
|
23
|
|
24 project=$(composeGetProject)
|
|
25
|
|
26 #If the project is empty, we want to stop the process because this is being run from the wrong directory
|
|
27
|
|
28 if [ "$project" == "" ]; then
|
|
29
|
|
30 echo "no project available"
|
|
31
|
|
32 exit 1
|
|
33
|
|
34 fi
|
|
35
|
|
36 echo "project is $project"
|
|
37 echo "Remote target is $remoteTarget"
|
|
38 echo "Username is $userName"
|
|
39
|
|
40
|
|
41 backupFile1=$(ls ./backup/*usasdb*.backup.gz | tail -n 1)
|
|
42 backupFile2=$(ls ./backup/*uspsdb*.backup.gz | tail -n 1)
|
|
43
|
|
44
|
|
45 #Create remote directory before scp
|
|
46 host=`echo $userName@$remoteTarget | sed -e 's/:.*//'`
|
|
47
|
|
48 target=`echo $remoteTarget | sed -e 's/.*://'`
|
|
49
|
|
50
|
|
51 ssh $host mkdir -p $target/$project
|
|
52
|
|
53 #SCP files
|
|
54 #
|
|
55 scp ${backupFile1} ${backupFile2} $userName@$remoteTarget/$project
|
|
56
|
|
57 echo " "
|
|
58
|
|
59 echo "completed sending ${backupFile1} and ${backupFile2} to ${remoteTarget}/${project} as user $userName"
|
|
60
|
|
61
|