annotate scripts/remote-backup-existing.sh @ 332:aafdbfc9623b

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