-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
executable file
·38 lines (33 loc) · 1006 Bytes
/
main.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
function init(){
export PGPASSFILE=$HOME/.pgpass
echo "$POSTGRES_HOST:$POSTGRES_PORT:$POSTGRES_DB:$POSTGRES_USER:$POSTGRES_PASSWORD" > $PGPASSFILE
chmod 600 $PGPASSFILE
}
function take_dump(){
$PGDUMP_BIN -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -d $POSTGRES_DB > $DUMP_FILE
}
function upload_2_s3(){
echo "copying $DUMP_FILE to s3..."
S3_URL="s3://$BUCKET_NAME/$BUCKET_PATH"
STAMP=$(date +%F-%H-%M-%S)
CMD="/opt/aws s3 cp --no-progress --storage-class STANDARD_IA $DUMP_FILE $S3_URL/${POSTGRES_DB}_${STAMP}.sql"
echo $CMD
eval ${CMD}
}
function notify_slack(){
echo "$@"
# TODO: implement this later
# $SLACKTEE_SH_BIN "@"
}
function handler () {
#EVENT_DATA=$1
#RESPONSE="{\"statusCode\": 200, \"body\": \"Hello from Lambda!\"}"
#echo $EVENT_DATA
export `cat .env|xargs`
init
take_dump
ls -lah $DUMP_FILE
upload_2_s3
ls -lah $DUMP_FILE
notify_slack "dumped and saved to s3" # not implemented
}