This repository has been archived by the owner on Nov 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
start.sh
executable file
·60 lines (47 loc) · 1.69 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
#! /bin/bash
# If first arg is bash, we'll just execute directly
if [ "$1" == "bash" ]; then
exec "$@"
exit 0
fi
# If no env variable set, get from command line
if [ "$OPT_ARGUMENTS" == "" ]; then
export OPT_ARGUMENTS="$@"
fi
# If key id is provied add arg
if [ -e "$GPG_KEY_ID" ]; then
export OPT_ARGUMENTS="$OPT_ARGUMENTS --encrypt-sign-key=\"$GPG_KEY_ID\""
fi
# If set to restore on start, restore if the data volume is empty
if [ "$RESTORE_ON_EMPTY_START" == "true" -a -z "$(ls -A $PATH_TO_BACKUP)" ]; then
/cron-exec.sh /restore.sh
fi
# Unless explicitly skipping, take a backup on startup
if [ "$SKIP_ON_START" != "true" ]; then
/cron-exec.sh /backup.sh
fi
if [ -n "$CRON_SCHEDULE" ]; then
# Export the environment to a file so it can be loaded from cron
env | sed 's/^\(.*\)=\(.*\)$/export \1="\2"/g' > /env.sh
# Remove some vars we don't want to keep
sed -i '/\(HOSTNAME\|affinity\|SHLVL\|PWD\)/d' /env.sh
# Use bash for cron
echo "SHELL=/bin/bash" > /crontab.conf
# Schedule the backups
echo "$CRON_SCHEDULE /cron-exec.sh /backup.sh" >> /crontab.conf
echo "Backups scheduled as $CRON_SCHEDULE"
if [ -n "$FULL_CRON_SCHEDULE" ]; then
echo "$FULL_CRON_SCHEDULE /cron-exec.sh /backup.sh full" >> /crontab.conf
echo "Full backup scheduled as $VERIFY_CRON_SCHEDULE"
fi
if [ -n "$VERIFY_CRON_SCHEDULE" ]; then
echo "$VERIFY_CRON_SCHEDULE /cron-exec.sh /verify.sh" >> /crontab.conf
echo "Verify scheduled as $VERIFY_CRON_SCHEDULE"
fi
# Add to crontab
crontab /crontab.conf
echo "Starting duplicity cron..."
cron
touch /cron.log /root/duplicity.log
tail -f /cron.log /root/duplicity.log
fi