From 31a7bac4b4520deb747c429df0ab3e73f19c1816 Mon Sep 17 00:00:00 2001 From: Manuel Molina Cuberos Date: Fri, 8 Dec 2017 22:20:53 +0100 Subject: Replaced operator '=~' with 'grep -Eq' and using a perl one-liner to avoid 'date -j'. Both are not compatible with Mac OS X Tiger. --- rsync_tmbackup.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index 104ee66..1bdd7cb 100755 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -54,6 +54,14 @@ fn_parse_date() { case "$OSTYPE" in linux*) date -d "${1:0:10} ${1:11:2}:${1:13:2}:${1:15:2}" +%s ;; cygwin*) date -d "${1:0:10} ${1:11:2}:${1:13:2}:${1:15:2}" +%s ;; + darwin8.0) yy=`expr ${1:0:4}` + mm=`expr ${1:5:2} - 1` + dd=`expr ${1:8:2}` + hh=`expr ${1:11:2}` + mi=`expr ${1:13:2}` + ss=`expr ${1:15:2}` + # Because under MacOS X Tiger 'date -j' doesn't work, we do this: + perl -e 'use Time::Local; print timelocal('$ss','$mi','$hh','$dd','$mm','$yy'),"\n";' ;; darwin*) date -j -f "%Y-%m-%d-%H%M%S" "$1" "+%s" ;; FreeBSD*) date -j -f "%Y-%m-%d-%H%M%S" "$1" "+%s" ;; esac @@ -76,14 +84,15 @@ fn_expire_backup() { } fn_parse_ssh() { - if [[ "$DEST_FOLDER" =~ ^[A-Za-z0-9\._%\+\-]+@[A-Za-z0-9.\-]+\:.+$ ]] + # To keep compatibility with bash version < 3, we use grep + if echo "$DEST_FOLDER"|grep -Eq '^[A-Za-z0-9\._%\+\-]+@[A-Za-z0-9.\-]+\:.+$' then SSH_USER=$(echo "$DEST_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\1/') SSH_HOST=$(echo "$DEST_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\2/') SSH_DEST_FOLDER=$(echo "$DEST_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\3/') SSH_CMD="ssh -p $SSH_PORT ${SSH_USER}@${SSH_HOST}" SSH_DEST_FOLDER_PREFIX="${SSH_USER}@${SSH_HOST}:" - elif [[ "$SRC_FOLDER" =~ ^[A-Za-z0-9\._%\+\-]+@[A-Za-z0-9.\-]+\:.+$ ]] + elif echo "$SRC_FOLDER"|grep -Eq '^[A-Za-z0-9\._%\+\-]+@[A-Za-z0-9.\-]+\:.+$' then SSH_USER=$(echo "$SRC_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\1/') SSH_HOST=$(echo "$SRC_FOLDER" | sed -E 's/^([A-Za-z0-9\._%\+\-]+)@([A-Za-z0-9.\-]+)\:(.+)$/\2/') -- cgit v1.2.3 From 19ecacad250d1f383f4728ebc42f70faadf7af94 Mon Sep 17 00:00:00 2001 From: Manuel Molina Cuberos Date: Sat, 9 Dec 2017 11:28:22 +0100 Subject: Newer versions of bash reports OSTYPE differently. This copes with the case. --- rsync_tmbackup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index 1bdd7cb..3d705cc 100755 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -54,7 +54,7 @@ fn_parse_date() { case "$OSTYPE" in linux*) date -d "${1:0:10} ${1:11:2}:${1:13:2}:${1:15:2}" +%s ;; cygwin*) date -d "${1:0:10} ${1:11:2}:${1:13:2}:${1:15:2}" +%s ;; - darwin8.0) yy=`expr ${1:0:4}` + darwin8*) yy=`expr ${1:0:4}` mm=`expr ${1:5:2} - 1` dd=`expr ${1:8:2}` hh=`expr ${1:11:2}` -- cgit v1.2.3 From bfa1fd092e8df1937bbeb911ab92b4f853578637 Mon Sep 17 00:00:00 2001 From: Nathan French Date: Fri, 19 Jan 2018 13:42:54 -0500 Subject: Fix to assure only one instance is running. Since this script runs under /usr/bin/env, running 'pgrep $0' will fail due to it being a child of 'bash'. In order to fix this, pgrep must use the `-o` flag (oldest pid, or in this case, the leader), and `-f` which searches the full process name. --- rsync_tmbackup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index 3d705cc..8df5969 100755 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -103,7 +103,7 @@ fn_parse_ssh() { } fn_run_cmd() { - if [ -n "$SSH_DEST_FOLDER_PREFIX" ] + if [ -n "$SSH_DEST_FOLDER_PREFIX" ] then eval "$SSH_CMD '$1'" else @@ -305,9 +305,9 @@ if [ -n "$(fn_find "$INPROGRESS_FILE")" ]; then fn_log_error "Previous backup task is still active - aborting (command: $RUNNINGCMD)." exit 1 fi - else + else RUNNINGPID="$(fn_run_cmd "cat $INPROGRESS_FILE")" - if [ "$RUNNINGPID" = "$(pgrep "$APPNAME")" ]; then + if [ "$RUNNINGPID" = "$(pgrep -o -f "$APPNAME")" ]; then fn_log_error "Previous backup task is still active - aborting." exit 1 fi -- cgit v1.2.3 From 80c4d26573131ca8aa9cc4a69e9391b3ccd20455 Mon Sep 17 00:00:00 2001 From: Loki3000 Date: Fri, 23 Feb 2018 12:25:36 +0300 Subject: Fix work with symlink as a destination https://github.com/laurent22/rsync-time-backup/issues/92 --- rsync_tmbackup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index 8df5969..07289d4 100755 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -68,7 +68,7 @@ fn_parse_date() { } fn_find_backups() { - fn_run_cmd "find "$DEST_FOLDER" -maxdepth 1 -type d -name \"????-??-??-??????\" -prune | sort -r" + fn_run_cmd "find "$DEST_FOLDER/" -maxdepth 1 -type d -name \"????-??-??-??????\" -prune | sort -r" } fn_expire_backup() { -- cgit v1.2.3