mirror of
https://github.com/laurent22/rsync-time-backup
synced 2024-09-20 14:31:56 +00:00
Sort fn_find_backups newest first.
This commit is contained in:
parent
9ece9fbec3
commit
08d090f19c
1 changed files with 6 additions and 6 deletions
|
@ -40,7 +40,7 @@ fn_parse_date() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn_find_backups() {
|
fn_find_backups() {
|
||||||
find "$DEST_FOLDER" -type d -name "????-??-??-??????" -prune
|
find "$DEST_FOLDER" -type d -name "????-??-??-??????" -prune | sort -r
|
||||||
}
|
}
|
||||||
|
|
||||||
fn_expire_backup() {
|
fn_expire_backup() {
|
||||||
|
@ -108,7 +108,7 @@ export IFS=$'\n' # Better for handling spaces in filenames.
|
||||||
PROFILE_FOLDER="$HOME/.rsync_tmbackup"
|
PROFILE_FOLDER="$HOME/.rsync_tmbackup"
|
||||||
LOG_FILE="$PROFILE_FOLDER/$NOW.log"
|
LOG_FILE="$PROFILE_FOLDER/$NOW.log"
|
||||||
DEST=$DEST_FOLDER/$NOW
|
DEST=$DEST_FOLDER/$NOW
|
||||||
PREVIOUS_DEST=$(fn_find_backups | sort | tail -n 1)
|
PREVIOUS_DEST=$(fn_find_backups | head -n 1)
|
||||||
INPROGRESS_FILE=$DEST_FOLDER/backup.inprogress
|
INPROGRESS_FILE=$DEST_FOLDER/backup.inprogress
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
@ -129,10 +129,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.
|
||||||
fn_log_info "$INPROGRESS_FILE already exists - the previous backup failed or was interrupted. Backup will resume from there."
|
fn_log_info "$INPROGRESS_FILE already exists - the previous backup failed or was interrupted. Backup will resume from there."
|
||||||
LINE_COUNT=$(fn_find_backups | sort | tail -n 2 | wc -l)
|
LINE_COUNT=$(fn_find_backups | wc -l)
|
||||||
mv -- "$PREVIOUS_DEST" "$DEST"
|
mv -- "$PREVIOUS_DEST" "$DEST"
|
||||||
if [ "$LINE_COUNT" -gt 1 ]; then
|
if [ "$LINE_COUNT" -gt 1 ]; then
|
||||||
PREVIOUS_PREVIOUS_DEST=$(fn_find_backups | sort | tail -n 2 | head -n 1)
|
PREVIOUS_PREVIOUS_DEST=$(fn_find_backups | sed -n '2p')
|
||||||
PREVIOUS_DEST=$PREVIOUS_PREVIOUS_DEST
|
PREVIOUS_DEST=$PREVIOUS_PREVIOUS_DEST
|
||||||
else
|
else
|
||||||
PREVIOUS_DEST=""
|
PREVIOUS_DEST=""
|
||||||
|
@ -173,7 +173,7 @@ while [ "1" ]; do
|
||||||
|
|
||||||
# Default value for $prev ensures that the most recent backup is never deleted.
|
# Default value for $prev ensures that the most recent backup is never deleted.
|
||||||
prev="0000-00-00-000000"
|
prev="0000-00-00-000000"
|
||||||
for fname in $(fn_find_backups | sort -r); do
|
for fname in $(fn_find_backups); do
|
||||||
date=$(basename "$fname")
|
date=$(basename "$fname")
|
||||||
stamp=$(fn_parse_date $date)
|
stamp=$(fn_parse_date $date)
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ while [ "1" ]; do
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OLD_BACKUP_PATH=$(fn_find_backups | head -n 1)
|
OLD_BACKUP_PATH=$(fn_find_backups | tail -n 1)
|
||||||
if [ "$OLD_BACKUP_PATH" == "" ]; then
|
if [ "$OLD_BACKUP_PATH" == "" ]; then
|
||||||
fn_log_error "No space left on device, and cannot get path to oldest backup to delete."
|
fn_log_error "No space left on device, and cannot get path to oldest backup to delete."
|
||||||
exit 1
|
exit 1
|
||||||
|
|
Loading…
Reference in a new issue