docker-duplicity-cron/start.sh

62 lines
1.7 KiB
Bash
Raw Normal View History

2017-03-19 00:11:03 +00:00
#! /bin/bash
2020-02-14 20:12:07 +00:00
set -euf
2017-03-19 00:11:03 +00:00
2017-07-17 02:37:16 +00:00
# If first arg is bash, we'll just execute directly
2020-02-14 20:12:07 +00:00
if [ $# -gt 0 ] && [ "$1" == "bash" ]; then
2017-03-19 00:11:03 +00:00
exec "$@"
exit 0
fi
2017-07-17 02:37:16 +00:00
# If no env variable set, get from command line
if [ "$OPT_ARGUMENTS" == "" ]; then
2020-02-14 20:12:07 +00:00
export OPT_ARGUMENTS="$*"
2017-07-17 02:37:16 +00:00
fi
2017-06-29 06:28:48 +00:00
# If key id is provied add arg
2020-02-14 20:12:07 +00:00
if [ -n "$GPG_KEY_ID" ]; then
2017-07-17 02:37:16 +00:00
export OPT_ARGUMENTS="$OPT_ARGUMENTS --encrypt-sign-key=\"$GPG_KEY_ID\""
2017-06-29 06:28:48 +00:00
fi
2018-03-10 01:29:41 +00:00
# If set to restore on start, restore if the data volume is empty
2020-02-14 20:12:07 +00:00
if [ "$RESTORE_ON_EMPTY_START" == "true" ] && [ -z "$(ls -A "$PATH_TO_BACKUP")" ]; then
2019-02-01 21:48:00 +00:00
/cron-exec.sh /restore.sh
2018-03-10 01:29:41 +00:00
fi
# Unless explicitly skipping, take a backup on startup
2017-03-19 00:11:03 +00:00
if [ "$SKIP_ON_START" != "true" ]; then
2019-02-01 21:48:00 +00:00
/cron-exec.sh /backup.sh
2017-03-19 00:11:03 +00:00
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
2017-03-19 00:11:03 +00:00
# Remove some vars we don't want to keep
sed -i '/\(HOSTNAME\|affinity\|SHLVL\|PWD\)/d' /env.sh
2017-03-19 00:11:03 +00:00
# Use bash for cron
echo "SHELL=/bin/bash" > /crontab.conf
# Schedule the backups
2019-02-01 21:48:00 +00:00
echo "$CRON_SCHEDULE /cron-exec.sh /backup.sh" >> /crontab.conf
2017-03-19 00:11:03 +00:00
echo "Backups scheduled as $CRON_SCHEDULE"
if [ -n "$FULL_CRON_SCHEDULE" ]; then
2019-02-01 21:48:00 +00:00
echo "$FULL_CRON_SCHEDULE /cron-exec.sh /backup.sh full" >> /crontab.conf
echo "Full backup scheduled as $VERIFY_CRON_SCHEDULE"
fi
2017-03-19 00:11:03 +00:00
if [ -n "$VERIFY_CRON_SCHEDULE" ]; then
2019-02-01 21:48:00 +00:00
echo "$VERIFY_CRON_SCHEDULE /cron-exec.sh /verify.sh" >> /crontab.conf
2017-03-19 00:11:03 +00:00
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