Mercurial > public > ssdt-docker
comparison scripts/remote-backup-existing.sh @ 329:5014e2b0e5d3
adding script per Ryan at MCOECN
author | aldrich@ssdt-ohio.org |
---|---|
date | Mon, 13 Jan 2020 12:57:03 +0000 |
parents | |
children | 20f86a321306 |
comparison
equal
deleted
inserted
replaced
328:1f0ff7540734 | 329:5014e2b0e5d3 |
---|---|
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 | |
8 # The file will also be placed on the specified remote target | |
9 # The format of the output is a compressed pg_dump (sql) format. | |
10 # | |
11 # | |
12 # This will send both usasdb and uspsdb, | |
13 # along with the top level contents of the project directory | |
14 #Environment variables can be used for REMOTE_BACKUP_TARGET and REMOTE_USERNAME | |
15 remoteTarget=${1:-$REMOTE_BACKUP_TARGET} | |
16 userName=${2:-$REMOTE_USERNAME} | |
17 projectDir=${3:-$PWD} | |
18 | |
19 cd $projectDir | |
20 | |
21 source "${SSDT_SCRIPTS:-$(dirname "${BASH_SOURCE[0]}")}/.functions.sh" | |
22 | |
23 set -o pipefail | |
24 | |
25 project=$(composeGetProject) | |
26 | |
27 #If the project is empty, we want to stop the process because this is being run from the wrong directory | |
28 | |
29 if [ "$project" == "" ]; then | |
30 | |
31 echo "no project available" | |
32 | |
33 exit 1 | |
34 | |
35 fi | |
36 | |
37 echo "project is $project" | |
38 echo "Remote target is $remoteTarget" | |
39 echo "Username is $userName" | |
40 | |
41 | |
42 backupFile1=$(ls ./backup/*usasdb*.backup.gz | tail -n 1) | |
43 backupFile2=$(ls ./backup/*uspsdb*.backup.gz | tail -n 1) | |
44 | |
45 | |
46 #Create remote directory before scp | |
47 host=`echo $userName@$remoteTarget | sed -e 's/:.*//'` | |
48 | |
49 target=`echo $remoteTarget | sed -e 's/.*://'` | |
50 | |
51 | |
52 ssh $host mkdir -p $target/$project | |
53 | |
54 #SCP files | |
55 # | |
56 scp ${backupFile1} ${backupFile2} $userName@$remoteTarget/$project | |
57 | |
58 echo " " | |
59 | |
60 echo "completed sending ${backupFile1} and ${backupFile2} to ${remoteTarget}/${project} as user $userName" | |
61 | |
62 |