forked from istepanov/docker-backup-to-s3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
32 lines (28 loc) · 894 Bytes
/
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
#!/bin/bash
set -e
: ${ACCESS_KEY:?"ACCESS_KEY env variable is required"}
: ${SECRET_KEY:?"SECRET_KEY env variable is required"}
: ${S3_PATH:?"S3_PATH env variable is required"}
export DATA_PATH=${DATA_PATH:-/data/}
CRON_SCHEDULE=${CRON_SCHEDULE:-0 1 * * *}
echo "access_key=$ACCESS_KEY" >> /root/.s3cfg
echo "secret_key=$SECRET_KEY" >> /root/.s3cfg
if [[ "$1" == 'no-cron' ]]; then
exec /sync.sh
elif [[ "$1" == 'get' ]]; then
exec /get.sh
elif [[ "$1" == 'delete' ]]; then
exec /usr/local/bin/s3cmd del -r "$S3_PATH"
else
LOGFIFO='/var/log/cron.fifo'
if [[ ! -e "$LOGFIFO" ]]; then
mkfifo "$LOGFIFO"
fi
CRON_ENV="PARAMS='$PARAMS'"
CRON_ENV="$CRON_ENV\nDATA_PATH='$DATA_PATH'"
CRON_ENV="$CRON_ENV\nS3_PATH='$S3_PATH'"
echo -e "$CRON_ENV\n$CRON_SCHEDULE /sync.sh > $LOGFIFO 2>&1" | crontab -
crontab -l
cron
tail -f "$LOGFIFO"
fi