-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_lib.shlib
More file actions
115 lines (98 loc) · 2.92 KB
/
_lib.shlib
File metadata and controls
115 lines (98 loc) · 2.92 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# l: Save location. s3 or local
# d: The subfolder to use inside /backup when using the local save
# location or inside $BUCKET/$S3_PREFIX when using s3
# f: Filename (without extension)
# e: Move the extracted DB backup file here after extraction
# s: This is a scheduled backup (organises into daily/weekly/monthly sub-folders)
grab_opts() {
IS_SCHEDULED=0
while getopts 'l:d:f:e:s' c
do
case $c in
l)
if [ "$OPTARG" = "local" ]; then
SAVE_LOCATION=$OPTARG
elif [ "$OPTARG" = "s3" ]; then
SAVE_LOCATION=$OPTARG
fi
;;
d) SUB_FOLDER=$OPTARG ;;
f) FILENAME=$OPTARG ;;
e) EXTRACT_TO=$OPTARG ;;
s) IS_SCHEDULED=1 ;;
esac
done
if [ -z "${SAVE_LOCATION}" ]; then
echo "Invalid option for -l. Use either 'local' or 's3'."
exit 1
fi
}
aws_init() {
if [ "${S3_ACCESS_KEY_ID}" = "**None**" ]; then
echo "You need to set the S3_ACCESS_KEY_ID environment variable."
exit 1
fi
if [ "${S3_SECRET_ACCESS_KEY}" = "**None**" ]; then
echo "You need to set the S3_SECRET_ACCESS_KEY environment variable."
exit 1
fi
if [ "${S3_BUCKET}" = "**None**" ]; then
echo "You need to set the S3_BUCKET environment variable."
exit 1
fi
aws configure set default.s3.signature_version s3v4
if [ "${S3_ENDPOINT}" == "**None**" ]; then
AWS_ARGS=""
else
AWS_ARGS="--endpoint-url ${S3_ENDPOINT}"
fi
# env vars needed for aws tools
export AWS_ACCESS_KEY_ID=$S3_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY
export AWS_DEFAULT_REGION=$S3_REGION
if [ -z ${S3_PREFIX} ]; then
S3_PREFIX="/"
else
S3_PREFIX="/${S3_PREFIX}/"
fi
if [ -z ${SUB_FOLDER} ]; then
SUB_FOLDER=""
else
case $SUB_FOLDER in
daily|weekly|monthly) SCHEDULE_TYPE=$SUB_FOLDER ;;
esac
SUB_FOLDER="${SUB_FOLDER}/"
fi
S3_KEY=${S3_PREFIX:1}${SUB_FOLDER}${FILENAME}.sql.xz
FULL_PATH=${S3_BUCKET}${S3_PREFIX}${SUB_FOLDER}${FILENAME}.sql.xz
}
local_init() {
if [ -z ${SUB_FOLDER} ]; then
SUB_FOLDER=""
else
SUB_FOLDER="${SUB_FOLDER}/"
mkdir -p /backup/${SUB_FOLDER}
fi
FULL_PATH=/backup/${SUB_FOLDER}${FILENAME}.sql.xz
}
postgres_init() {
if [ "${POSTGRES_HOST}" = "**None**" ]; then
if [ -n "${POSTGRES_PORT_5432_TCP_ADDR}" ]; then
POSTGRES_HOST=$POSTGRES_PORT_5432_TCP_ADDR
POSTGRES_PORT=$POSTGRES_PORT_5432_TCP_PORT
else
echo "You need to set the POSTGRES_HOST environment variable."
exit 1
fi
fi
if [ "${POSTGRES_USER}" = "**None**" ]; then
echo "You need to set the POSTGRES_USER environment variable."
exit 1
fi
if [ "${POSTGRES_PASSWORD}" = "**None**" ]; then
echo "You need to set the POSTGRES_PASSWORD environment variable or link to a container named POSTGRES."
exit 1
fi
export PGPASSWORD=$POSTGRES_PASSWORD
POSTGRES_HOST_OPTS="-h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER $POSTGRES_EXTRA_OPTS"
}