This repository has been archived on 2022-12-04. You can view files and clone it, but cannot push or open issues or pull requests.
rsync-docker/rsync.sh

48 lines
1.1 KiB
Bash
Raw Normal View History

2020-04-12 21:43:33 +00:00
#!/bin/sh
# rsync.sh - a script to configure the rsync job in the container
### PREPARATION
echo "Preparation steps started."
# should logs be created?
if [ "$RSYNC_LOG" != "" ]; then
# logging enabled
echo "Logging selected."
# the specific name is to be used
LOG_COMMAND=" >> /rsync/logs/$RSYNC_LOG"'.$(date +%Y%m%d-%H%M).log 2>&1'
echo "Logging command is $LOG_COMMAND"
else
# no logs
echo "Logging NOT selected."
LOG_COMMAND=""
fi
# run as a cron job?
if [ "$RSYNC_CRON" != "" ]; then
# yes, run it as a cron job
echo "Running rsync as a cron job selected."
# make a crontab entry
#shift
echo "$RSYNC_CRON rsync $@$LOG_COMMAND" >> /etc/crontabs/root
echo "Entry created in the crontab"
else
# no cron job
echo "Running rsync as a cron job NOT selected."
fi
echo "Preparation steps completed."
### EXECUTION
if [ "$RSYNC_CRON" != "" ]; then
# run as a cron job, start the cron daemon
echo "Starting the cron daemon..."
crond -f
else
# one time run
echo "Executing rsync as an one time run..."
eval rsync $@"$LOG_COMMAND"
fi