From 7ff771ce13f3a73d1615a629f234db2e603f22d9 Mon Sep 17 00:00:00 2001 From: Stefan Sterz Date: Sun, 18 Mar 2018 11:48:57 +0100 Subject: [PATCH] fix: fix weekly backup --- README.md | 3 +++ backup.sh | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 49bccd6..f78af3b 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,9 @@ FROMSSHUSER="" # The ssh user of the system from which the # files will be backed up FROMSSHPORT=22 # The ssh port of the system from which the # files will be backed up +WEEKS=5 # For how many weeks shall we save backups? + # This will keep weekly backups for at most 5 + # weeks. ``` ### Crontab example diff --git a/backup.sh b/backup.sh index c394b24..84f49fc 100755 --- a/backup.sh +++ b/backup.sh @@ -25,11 +25,11 @@ FROMSSHUSER="" # The ssh user of the system from which the # files will be backed up FROMSSHPORT=22 # The ssh port of the system from which the # files will be backed up - +WEEKS=5 # For how many weeks shall we save backups? ## Command variables, # These should be fine, but if something doesn't work these can be adjusted -MOUNT="/bin/mount"; FGREP="/bin/fgrep"; SSH="/usr/bin/ssh" +MOUNT="/bin/mount"; FGREP="/bin/fgrep"; SSH="/usr/bin/ssh"; EXPR="/usr/bin/expr" LN="/bin/ln"; ECHO="/bin/echo"; DATE="/bin/date"; MKDIR="/bin/mkdir" DPKG="/usr/bin/dpkg"; AWK="/usr/bin/awk"; MAIL="/usr/bin/mail" CUT="/usr/bin/cut"; TR="/usr/bin/tr"; RSYNC="/usr/bin/rsync" @@ -139,6 +139,7 @@ WEEKDAY=$($DATE +"%u") # %a = weekday as number DAY=$($DATE +"%d") # %d = day in month as number MONTH=$($DATE +%m) # %m = month as number HOUR=$($DATE +"%H") # %H = hour as number +WEEK=$($EXPR $($DATE +"%W") % $WEEKS) # %W = week as number, used to save backups for the past $WEEKS weeks # Create a backup every first day in a month if [[ $DAY = 01 ]]; then @@ -147,7 +148,6 @@ fi # Create a special backup approx every week if [[ $WEEKDAY = 7 ]]; then - let WEEK=$($DATE +"%W")%5 # save past 5 weeks backup "weekly/$WEEK" fi