summaryrefslogtreecommitdiff
path: root/rsync_tmbackup.sh
diff options
context:
space:
mode:
authorMatthias Kern <m.kern@protonmail.com>2017-11-24 20:16:22 +0100
committerMatthias Kern <m.kern@protonmail.com>2017-11-24 20:16:22 +0100
commitc5c1307062c31072c9a0b46ba9605a281d49638a (patch)
tree90adfa20698c27bf04c30ee200e71df62f34d86a /rsync_tmbackup.sh
parentd13af58252b52cb6825799de14dd264810ad82a8 (diff)
Introduces function that parses the --strategy option into a two dimensional array
Diffstat (limited to 'rsync_tmbackup.sh')
-rwxr-xr-xrsync_tmbackup.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh
index 104ee66..4713924 100755
--- a/rsync_tmbackup.sh
+++ b/rsync_tmbackup.sh
@@ -59,6 +59,26 @@ fn_parse_date() {
esac
}
+fn_parse_strategy() {
+ # The current set (x,y) of the two parameters (after x days, keep y number of backups)
+ STRATEGY_ARRAY=()
+
+ # STRATEGY without comma
+ NO_COMMAS=$(echo $STRATEGY | sed "s/,//g")
+
+ # Extracts an array of three pairs of elements from the --strategy option
+ IFS=' '
+ PARAMETER_ARRAY=(`echo ${NO_COMMAS}`)
+
+ # Build the expiration strategy matrix
+ for ((i=0; i<3; i++));
+ do
+ STRATEGY_ARRAY=($(echo ${PARAMETER_ARRAY[i]} | sed "s/:/ /g"))
+ EXPIRATION_STRATEGY_MATRIX[$i,0]=${STRATEGY_ARRAY[0]}
+ EXPIRATION_STRATEGY_MATRIX[$i,1]=${STRATEGY_ARRAY[1]}
+ done
+}
+
fn_find_backups() {
fn_run_cmd "find "$DEST_FOLDER" -maxdepth 1 -type d -name \"????-??-??-??????\" -prune | sort -r"
}
@@ -148,6 +168,8 @@ DEST_FOLDER=""
EXCLUSION_FILE=""
LOG_DIR="$HOME/.$APPNAME"
AUTO_DELETE_LOG="1"
+STRATEGY="1:1, 30:7, 365:30"
+declare -A EXPIRATION_STRATEGY_MATRIX
RSYNC_FLAGS="-D --compress --numeric-ids --links --hard-links --one-file-system --itemize-changes --times --recursive --perms --owner --group --stats --human-readable"
@@ -170,6 +192,10 @@ while :; do
shift
RSYNC_FLAGS="$1"
;;
+ --strategy)
+ shift
+ STRATEGY="$1"
+ ;;
--log-dir)
shift
LOG_DIR="$1"
@@ -350,6 +376,14 @@ while : ; do
# Purge certain old backups before beginning new backup.
# -----------------------------------------------------------------------------
+ # Parses the --strategy option and creates a matrix of its elements
+ fn_parse_strategy "$STRATEGY"
+ # Prints out the expiration strategy matrix (for debugging purpose only)
+ echo "After" ${EXPIRATION_STRATEGY_MATRIX[0,0]} "days keep a backup every" ${EXPIRATION_STRATEGY_MATRIX[0,1]} "days"
+ echo "After" ${EXPIRATION_STRATEGY_MATRIX[1,0]} "days keep a backup every" ${EXPIRATION_STRATEGY_MATRIX[1,1]} "days"
+ echo "After" ${EXPIRATION_STRATEGY_MATRIX[2,0]} "days keep a backup every" ${EXPIRATION_STRATEGY_MATRIX[2,1]} "days"
+
+
# Default value for $PREV ensures that the most recent backup is never deleted.
PREV="0000-00-00-000000"
for FILENAME in $(fn_find_backups | sort -r); do