summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrastkov <rastkov@gmail.com>2013-11-01 14:32:59 +0100
committerrastkov <rastkov@gmail.com>2013-11-01 14:32:59 +0100
commit99258d80abc2411e14a4ead5cdc019842b322d6e (patch)
tree640e11718a1fc9cd3320fee39c56991b790f2129
parent27a0a1881f36ce41fc5d6f21de2df9f96e812339 (diff)
Update rsync_tmbackup.sh
Set LAST_TIME, LINE_CONUT and SECOND_LAST_TIME based on `uname -s` output for Mac OS compatibility.
-rw-r--r--rsync_tmbackup.sh23
1 files changed, 19 insertions, 4 deletions
diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh
index 60adb6a..8a0909c 100644
--- a/rsync_tmbackup.sh
+++ b/rsync_tmbackup.sh
@@ -39,7 +39,23 @@ fi
NOW=$(date +"%Y-%m-%d-%H%M%S")
DEST=$DEST_FOLDER/$NOW
-LAST_TIME=$(find $DEST_FOLDER -maxdepth 1 -type d -regextype posix-extended -regex "^.*[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}" | sort | tail -n 1)
+
+# Set LAST_TIME, LINE_CONUT and SECOND_LAST_TIME based on uname -s output for Mac OS compatibility
+# I guess there might be an more elegant way to do this
+case `uname -s` in
+ Darwin)
+ LAST_TIME=$(find -E $DEST_FOLDER -type d -iregex "./[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}" -prune | sort | tail -n 1)
+ LINE_COUNT=$(find -E $DEST_FOLDER -type d -iregex "./[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}" -prune | sort | tail -n 2 | wc -l)
+ SECOND_LAST_TIME=$(find -E $DEST_FOLDER -type d -iregex "./[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}" -prune | sort | tail -n 2 | head -n 1)
+ ;;
+
+ *)
+ LAST_TIME=$(find $DEST_FOLDER -type d -regextype posix-extended -regex "^.*[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}" -prune | sort | tail -n 1)
+ LINE_COUNT=$(find $DEST_FOLDER -type d -regextype posix-extended -regex "^.*[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}" -prune | sort | tail -n 2 | wc -l)
+ SECOND_LAST_TIME=$(find $DEST_FOLDER -type d -regextype posix-extended -regex "^.*[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}" -prune | sort | tail -n 2 | head -n 1)
+ ;;
+esac
+
PREVIOUS_DEST=$LAST_TIME
INPROGRESS_FILE=$DEST_FOLDER/backup.inprogress
@@ -52,10 +68,9 @@ if [ -f "$INPROGRESS_FILE" ]; then
# - Last backup is moved to current backup folder so that it can be resumed.
# - 2nd to last backup becomes last backup.
echo "$INPROGRESS_FILE already exists - the previous backup failed or was interrupted. Backup will resume from there."
- LINE_COUNT=$(find $DEST_FOLDER -maxdepth 1 -type d -regextype posix-extended -regex "^.*[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}" | sort | tail -n 2 | wc -l)
+
mv $PREVIOUS_DEST $DEST
- if [ "$LINE_COUNT" -gt 1 ]; then
- SECOND_LAST_TIME=$(find $DEST_FOLDER -maxdepth 1 -type d -regextype posix-extended -regex "^.*[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{6}" | sort | tail -n 2 | head -n 1)
+ if [ "$LINE_COUNT" -gt 1 ]; then
LAST_TIME=$SECOND_LAST_TIME
else
LAST_TIME=""