mirror of
https://github.com/lobaro/restic-backup-docker.git
synced 2026-02-17 09:23:56 +00:00
46 lines
998 B
Bash
Executable File
46 lines
998 B
Bash
Executable File
#!bin/sh
|
|
|
|
echo "Starting container ..."
|
|
|
|
RESTIC_CMD=restic
|
|
|
|
if [ -n "${ROOT_CERT}" ]; then
|
|
RESTIC_CMD="${RESTIC_CMD} --cert ${ROOT_CERT}"
|
|
fi
|
|
|
|
if [ -n "${NFS_TARGET}" ]; then
|
|
echo "Mounting NFS based on NFS_TARGET: ${NFS_TARGET}"
|
|
mount -o nolock -v ${NFS_TARGET} /mnt/restic
|
|
fi
|
|
|
|
restic snapshots &>/dev/null
|
|
status=$?
|
|
echo "Check Repo status $status"
|
|
|
|
if [ $status != 0 ]; then
|
|
echo "Restic repository '${RESTIC_REPOSITORY}' does not exists. Running restic init."
|
|
restic init
|
|
|
|
init_status=$?
|
|
echo "Repo init status $init_status"
|
|
|
|
if [ $init_status != 0 ]; then
|
|
echo "Failed to init the repository: '${RESTIC_REPOSITORY}'"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
echo "Setup backup cron job with cron expression BACKUP_CRON: ${BACKUP_CRON}"
|
|
echo "${BACKUP_CRON} /bin/backup >> /var/log/cron.log 2>&1" > /var/spool/cron/crontabs/root
|
|
|
|
# Make sure the file exists before we start tail
|
|
touch /var/log/cron.log
|
|
|
|
# start the cron deamon
|
|
crond
|
|
|
|
echo "Container started."
|
|
|
|
exec "$@" |