diff --git a/README.md b/README.md index 2e21f46..960503a 100644 --- a/README.md +++ b/README.md @@ -104,3 +104,10 @@ As you maybe noticed already before, `restic-backup.service` is configured to st Once in a while it can be good to do a health check of the remote repository, to make sure it's not getting corrupt. This can be done with `$ restic check`. There are some `*-check*`-files in this git repo. Install these in the same way you installed the `*-backup*`-files. + + +## Cron? +If you want to run an all-classic cron job instead, do like this: + +* `etc/cron.d/restic`: Depending on your system's cron, put this in `/etc/cron.d/` or similar, or copy the contents to $(sudo crontab -e). The format of this file is tested under FreeBSD, and might need adaptions depending on your cron. +* `usr/local/sbin/cron_mail`: A wrapper for running cron jobs, that sends output of the job as an email using the mail(1) command. diff --git a/etc/cron.d/restic b/etc/cron.d/restic new file mode 100644 index 0000000..b510fc0 --- /dev/null +++ b/etc/cron.d/restic @@ -0,0 +1,8 @@ +SHELL=/bin/sh +PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin/:/usr/local/sbin/ +# Order of crontab fields +# minute hour mday month wday command +# Reference: https://www.freebsd.org/doc/handbook/configtuning-cron.html +# Reference: crontab(5). +@midnight root cron_mail restic_backup.sh +@monthly root cron_mail restic_check.sh diff --git a/usr/local/sbin/cron_mail b/usr/local/sbin/cron_mail new file mode 100755 index 0000000..c3dd692 --- /dev/null +++ b/usr/local/sbin/cron_mail @@ -0,0 +1,24 @@ +#!/usr/bin/env sh +# vi: ft=sh +# +# To be called by a cron job as a wrapper that sends stdour and stderr via the mail program. +# Why? Because of FreeBSD the system cron uses sendmail, and I want to use ssmtp. +# Make your crontab files like: +#SHELL=/bin/sh +#PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin +#@daily root cron_mail freebsd-update cron + +mail_target=root +scriptname=${0##*/} + +if [ $# -eq 0 ]; then + echo "No program to run given!" >&2 + exit 1 +fi +cmd="$@" + +body=$(eval "$cmd" 2>&1) + +if [ -n "$body" ];then + echo "$body" | mail -s "${scriptname}: ${cmd}" $mail_target +fi