#!/usr/bin/zsh set -x PRETEND="no" function run_rsnapshot() { rsnapshot -c /etc/rsnapshot.conf $1 } while true; do NOW=$(date +"%Y-%m-%d %H:%M:%S") TIME=$(date --date="$NOW" +"%H:%M:%S") DATE=$(date --date="$NOW" +"%Y-%m-%d") TOMORROW=$(date --date="$NOW + 1 day" +"%Y-%m-%d") OVERNIGHT="no" if dateutils.dtest "$TIME" --gt "20:00:00" && dateutils.dtest "$NOW" --lt "$TOMORROW 08:00:00"; then if [[ $PRETEND != "yes" ]]; then echo "daily:beta" run_rsnapshot beta fi if [[ $(date +%A) == "Sunday" ]]; then echo "Sunday -> weekly:gamma" if [[ $PRETEND != "yes" ]]; then sleep 1800 # wait 30 minutes run_rsnapshot gamma fi fi if [[ $(date +%d) == "01" ]]; then echo "1st of a month -> monthly:delta" if [[ $PRETEND != "yes" ]]; then sleep 1800 # wait 30 minutes run_rsnapshot delta fi fi if [[ $(date +"%m-%d") == "01-01" ]]; then echo "1st day of the year -> yearly:epsilon" if [[ $PRETEND != "yes" ]]; then sleep 1800 # wait 30 minutes run_rsnapshot epsilon fi fi wakeup=$(date -d "$TOMORROW 08:00:00" +'%Y%m%d%H%M%S') next=$(date -d "$TOMORROW 08:00:00" +'%s') OVERNIGHT="yes" else echo "hourly:alpha" if [[ $PRETEND != "yes" ]]; then run_rsnapshot alpha fi wakeup=$(date -d "now + 1 hour" +'%Y%m%d%H5959') next=$(date -d "now + 1 hour" +'%s') OVERNIGHT="no" fi echo "NEXT" echo $next echo "WAKEUP" echo $wakeup sleep 15 # wait 15 seconds if [[ $PRETEND != "yes" ]]; then if [[ $OVERNIGHT == "yes" && $(users) == "" ]]; then rtcwake -m mem --date $wakeup else sleep $(( $next - $(date +%s) )) fi fi done