diff options
author | Patrick Simianer <pks@pks.rocks> | 2020-02-23 13:07:36 +0100 |
---|---|---|
committer | Patrick Simianer <pks@pks.rocks> | 2020-02-23 13:07:36 +0100 |
commit | 94f16565c7156db218bc8a6147083c9677a74d5e (patch) | |
tree | 3b222201df69c1e4030d9b24dec7f044e7f40c7f /rsnapshot-wrapper | |
parent | 214ff48933a1062008fa252fa5a5cad71c371e35 (diff) |
rsnapshot-wrapper
Diffstat (limited to 'rsnapshot-wrapper')
-rwxr-xr-x | rsnapshot-wrapper | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/rsnapshot-wrapper b/rsnapshot-wrapper new file mode 100755 index 0000000..724ea1a --- /dev/null +++ b/rsnapshot-wrapper @@ -0,0 +1,85 @@ +#!/usr/bin/zsh + +set -x + +PRETEND="no" + +run_rsnapshot() { + superfans set 75 + rsnapshot -c /etc/rsnapshot.conf $1 + superfans set 50 +} + +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" + run_rsnapshot daily + fi + + if [[ $(date +%A) == "Sunday" ]]; then + echo "Sunday -> weekly" + if [[ $PRETEND != "yes" ]]; then + sleep 1800 # wait 30 minutes + run_rsnapshot weekly + fi + fi + + if [[ $(date +%d) == "01" ]]; then + echo "1st of a month -> monthly" + if [[ $PRETEND != "yes" ]]; then + sleep 1800 # wait 30 minutes + run_rsnapshot monthly + fi + fi + + if [[ $(date +"%m-d") == "01-01" ]]; then + echo "1st day of the year -> yearly" + if [[ $PRETEND != "yes" ]]; then + sleep 1800 # wait 30 minutes + run_rsnapshot yearly + 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" + + if [[ $PRETEND != "yes" ]]; then + run_rsnapshot hourly + 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 + |