Update rsync_tmbackup.sh

Using find instead of ls to find the last and second last directory used for backup.
This commit is contained in:
rastkov
2013-10-29 12:07:30 +01:00
parent 1b0b115dd0
commit a40a733902
+5 -4
View File
@@ -39,8 +39,9 @@ fi
NOW=$(date +"%Y-%m-%d-%H%M%S") NOW=$(date +"%Y-%m-%d-%H%M%S")
DEST=$DEST_FOLDER/$NOW DEST=$DEST_FOLDER/$NOW
LAST_TIME=$(ls -1 $DEST_FOLDER | grep "\d\d\d\d-\d\d-\d\d-\d\d\d\d\d\d" | tail -n 1) LAST_TIME=$(find $DEST_FOLDER -maxdepth 1 -type d -iname "*-*[0-9]" | sort | tail -n 1)
PREVIOUS_DEST=$DEST_FOLDER/$LAST_TIME echo "############################################ $LAST_TIME"
PREVIOUS_DEST=$LAST_TIME
INPROGRESS_FILE=$DEST_FOLDER/backup.inprogress INPROGRESS_FILE=$DEST_FOLDER/backup.inprogress
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@@ -52,10 +53,10 @@ if [ -f "$INPROGRESS_FILE" ]; then
# - Last backup is moved to current backup folder so that it can be resumed. # - Last backup is moved to current backup folder so that it can be resumed.
# - 2nd to last backup becomes last backup. # - 2nd to last backup becomes last backup.
echo "$INPROGRESS_FILE already exists - the previous backup failed or was interrupted. Backup will resume from there." echo "$INPROGRESS_FILE already exists - the previous backup failed or was interrupted. Backup will resume from there."
LINE_COUNT=$(ls -1 $DEST_FOLDER | grep "\d\d\d\d-\d\d-\d\d-\d\d\d\d\d\d" | tail -n 2 | wc -l) LINE_COUNT=$(find $DEST_FOLDER -maxdepth 1 -type d -iname "*-*[0-9]" | sort | tail -n 2 | wc -l)
mv $PREVIOUS_DEST $DEST mv $PREVIOUS_DEST $DEST
if [ "$LINE_COUNT" -gt 1 ]; then if [ "$LINE_COUNT" -gt 1 ]; then
SECOND_LAST_TIME=$(ls -1 $DEST_FOLDER | grep "\d\d\d\d-\d\d-\d\d-\d\d\d\d\d\d" | tail -n 2 | head -n 1) SECOND_LAST_TIME=$(find $DEST_FOLDER -maxdepth 1 -type d -iname "*-*[0-9]" | sort | tail -n 2 | head -n 1)
LAST_TIME=$SECOND_LAST_TIME LAST_TIME=$SECOND_LAST_TIME
else else
LAST_TIME="" LAST_TIME=""