-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregenbash.sh
More file actions
79 lines (68 loc) · 1.99 KB
/
regenbash.sh
File metadata and controls
79 lines (68 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# Restore Neotoma from a database snapshot.
# by: Simon Goring
DOC_REQUEST=70
if [ "$1" = "-h" -o "$1" = "--help" ] # Request help.
then
echo; echo "Usage: $0 [dump-file-path]"; echo
sed --silent -e '/DOCUMENTATIONXX$/,/^DOCUMENTATIONXX$/p' "$0" |
sed -e '/DOCUMENTATIONXX$/d'; exit $DOC_REQUEST; fi
: <<DOCUMENTATIONXX
Restore the Neotoma Paleoecology Database Snapshot Locally
---------------------------------------------------------------
Mac & Linux:
The commandline parameter provides the path to the "dump" file that
is used to restore the Neotoma snapshot to a local database called
"neotoma". It should be noted that this script runs under the user's
profile. There are cases where individuals have set up PostgreSQL
to run under a different user's account.
DOCUMENTATIONXX
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
export PGPASSWORD=postgres
export PGUSER=postgres
export PGHOST=localhost
export PGPORT=5432
export PGDATABASE=postgres
for i in "$@"; do
case $i in
-W=*|--password=*)
PGPASSWORD="${i#*=}"
shift # past argument=value
;;
-d=*|--database=*)
PGDATABASE="${i#*=}"
shift # past argument=value
;;
-U=*|--user=*)
PGUSER="${i#*=}"
shift # past argument=value
;;
-p=*|--port=*)
PGPORT="${i#*=}"
shift # past argument=value
;;
-h=*|--host=*)
PGHOST="${i#*=}"
shift # past argument=value
;;
-*|--*)
echo "Unknown option $i"
exit 1
;;
*)
;;
esac
done
if [[ $(which psql) ]]; then
PG_VERSION=$(pg_config --version)
echo "postgres exists."
else
echo "Postgres does not seem to be installed on your computer."
exit 1
fi
echo "⛃ Setting up the local Neotoma database:"
psql -U ${PGUSER} -h ${PGHOST} -p ${PGPORT} -f dbsetup.sql
echo "Empty database is now set up."
echo " ▶ Restoring database content:"
psql -U $PGUSER -h $PGHOST -p $PGPORT -d postgres -f neotoma_clean*.dump
echo done.