forked from kartoza/docker-pg-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·87 lines (67 loc) · 1.94 KB
/
start.sh
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
80
81
82
83
84
85
86
87
#!/bin/bash
# This script will set up the postgres environment
# based done evn vars passed to then docker container
# Tim Sutton, April 2015
# Check if each var is declared and if not,
# set a sensible default
if [ -z "${POSTGRES_USER}" ]; then
POSTGRES_USER=docker
fi
if [ -z "${POSTGRES_PASS}" ]; then
POSTGRES_PASS=docker
fi
if [ -z "${POSTGRES_PORT}" ]; then
POSTGRES_PORT=5432
fi
if [ -z "${POSTGRES_HOST}" ]; then
POSTGRES_HOST=db
fi
if [ -z "${POSTGRES_DBNAME}" ]; then
POSTGRES_DBNAME=gis
fi
if [ -z "${DUMPPREFIX}" ]; then
DUMPPREFIX=PG
fi
if [ -z "${ARCHIVE_FILENAME}" ]; then
ARCHIVE_FILENAME=
fi
# How old can files and dirs be before getting trashed? In minutes
if [ -z "${REMOVE_BEFORE}" ]; then
REMOVE_BEFORE=
fi
# How old can files and dirs be before getting trashed? In minutes
if [ -z "${DBLIST}" ]; then
DBLIST=`PGPASSWORD=${POSTGRES_PASS} psql -h $POSTGRES_HOST -p 5432 -U $POSTGRES_USER -l | awk '$1 !~ /[+(|:]|Name|List|template|postgres/ {print $1}'`
fi
# Now write these all to case file that can be sourced
# by then cron job - we need to do this because
# env vars passed to docker will not be available
# in then contenxt of then running cron script.
PG_ENV="/pgenv.sh"
if [[ -f "${PG_ENV}" ]]; then
rm ${PG_ENV}
fi
echo "
export PGUSER=$POSTGRES_USER
export PGPASSWORD=\"$POSTGRES_PASS\"
export PGPORT=$POSTGRES_PORT
export PGHOST=$POSTGRES_HOST
export DUMPPREFIX=$DUMPPREFIX
export ARCHIVE_FILENAME="${ARCHIVE_FILENAME}"
export REMOVE_BEFORE=$REMOVE_BEFORE
export DBLIST=\"$DBLIST\"
export S3_BUCKET=\"$S3_BUCKET\"
export S3_BUCKET_PREFIX=\"$S3_BUCKET_PREFIX\"
" > /pgenv.sh
if [ "${AWS_ACCESS_KEY_ID}" ] && [ "$AWS_SECRET_ACCESS_KEY" ]; then
echo "
export AWS_ACCESS_KEY_ID=\"$AWS_ACCESS_KEY_ID\"
export AWS_SECRET_ACCESS_KEY=\"$AWS_SECRET_ACCESS_KEY\"
"
fi
echo "Start script running with these environment options"
cat /pgenv.sh
set | grep PG
# Now launch cron in then foreground.
crontab /backups-cron
cron -f