annotate scripts/remote-backup-existing.sh @ 564:429ab7060baf

use different version
author belknapSSDT <zach.belknap@mcoecn.org>
date Fri, 24 May 2024 10:37:11 -0400
parents dfae5707657d
children
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
334
ea21046c5e57 testing
aldrich
parents: 332
diff changeset
10 #
336
dfae5707657d testing remote
aldrich
parents: 335
diff changeset
11 # testing changes additional
329
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
12 # This will send both usasdb and uspsdb,
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
13 # along with the top level contents of the project directory
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
14 #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
15 remoteTarget=${1:-$REMOTE_BACKUP_TARGET}
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
16 userName=${2:-$REMOTE_USERNAME}
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
17 projectDir=${3:-$PWD}
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
18
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
19 cd $projectDir
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
20
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
21 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh"
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
22
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
23 set -o pipefail
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
24
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
25 project=$(composeGetProject)
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
26
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
27 #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
28
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
29 if [ "$project" == "" ]; then
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
30
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
31 echo "no project available"
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
32
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
33 exit 1
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
34
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
35 fi
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
36
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
37 echo "project is $project"
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
38 echo "Remote target is $remoteTarget"
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
39 echo "Username is $userName"
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
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
42 backupFile1=$(ls ./backup/*usasdb*.backup.gz | tail -n 1)
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
43 backupFile2=$(ls ./backup/*uspsdb*.backup.gz | tail -n 1)
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
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
46 #Create remote directory before scp
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
47 host=`echo $userName@$remoteTarget | sed -e 's/:.*//'`
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
48
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
49 target=`echo $remoteTarget | sed -e 's/.*://'`
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
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
52 ssh $host mkdir -p $target/$project
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
53
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
54 #SCP files
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
55 #
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
56 scp ${backupFile1} ${backupFile2} $userName@$remoteTarget/$project
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
57
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
58 echo " "
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
59
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
60 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
61
5014e2b0e5d3 adding script per Ryan at MCOECN
aldrich@ssdt-ohio.org
parents:
diff changeset
62