Rebase on @laurent22/master.
This commit is contained in:
+24
-32
@@ -57,8 +57,8 @@ SRC_FOLDER="${1%/}"
|
||||
DEST_FOLDER="${2%/}"
|
||||
EXCLUSION_FILE="$3"
|
||||
|
||||
for arg in "$SRC_FOLDER" "$DEST_FOLDER" "$EXCLUSION_FILE"; do
|
||||
if [[ "$arg" == *"'"* ]]; then
|
||||
for ARG in "$SRC_FOLDER" "$DEST_FOLDER" "$EXCLUSION_FILE"; do
|
||||
if [[ "$ARG" == *"'"* ]]; then
|
||||
fn_log_error 'Arguments may not have any single quote characters.'
|
||||
exit 1
|
||||
fi
|
||||
@@ -92,7 +92,6 @@ EPOCH=$(date "+%s")
|
||||
KEEP_ALL_DATE=$(($EPOCH - 86400)) # 1 day ago
|
||||
KEEP_DAILIES_DATE=$(($EPOCH - 2678400)) # 31 days ago
|
||||
|
||||
|
||||
export IFS=$'\n' # Better for handling spaces in filenames.
|
||||
PROFILE_FOLDER="$HOME/.$APPNAME"
|
||||
DEST="$DEST_FOLDER/$NOW"
|
||||
@@ -130,7 +129,7 @@ fi
|
||||
while : ; do
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Check if we are doing an incremental backup (if previous backup exists) or not
|
||||
# Check if we are doing an incremental backup (if previous backup exists).
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
LINK_DEST_OPTION=""
|
||||
@@ -157,28 +156,29 @@ while : ; do
|
||||
# Purge certain old backups before beginning new backup.
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# Default value for $prev ensures that the most recent backup is never deleted.
|
||||
prev="0000-00-00-000000"
|
||||
for fname in $(fn_find_backups); do
|
||||
date=$(basename "$fname")
|
||||
stamp=$(fn_parse_date $date)
|
||||
# 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
|
||||
BACKUP_DATE=$(basename "$FILENAME")
|
||||
TIMESTAMP=$(fn_parse_date $BACKUP_DATE)
|
||||
|
||||
# Skip if failed to parse date...
|
||||
[ -n "$stamp" ] || continue
|
||||
|
||||
if [ $stamp -ge $KEEP_ALL_DATE ]; then
|
||||
: # Don't expire any backups in this range
|
||||
|
||||
elif [ $stamp -ge $KEEP_DAILIES_DATE ]; then
|
||||
# Delete all but the most recent of each day.
|
||||
[ "${date:0:10}" == "${prev:0:10}" ] && fn_expire_backup "$fname"
|
||||
|
||||
else
|
||||
# Delete all but the most recent of each month.
|
||||
[ "${date:0:7}" == "${prev:0:7}" ] && fn_expire_backup "$fname"
|
||||
if [ -z "$TIMESTAMP" ]; then
|
||||
fn_log_warn "Could not parse date: $FILENAME"
|
||||
continue
|
||||
fi
|
||||
|
||||
prev=$date
|
||||
if [ $TIMESTAMP -ge $KEEP_ALL_DATE ]; then
|
||||
true
|
||||
elif [ $TIMESTAMP -ge $KEEP_DAILIES_DATE ]; then
|
||||
# Delete all but the most recent of each day.
|
||||
[ "${BACKUP_DATE:0:10}" == "${PREV:0:10}" ] && fn_expire_backup "$FILENAME"
|
||||
else
|
||||
# Delete all but the most recent of each month.
|
||||
[ "${BACKUP_DATE:0:7}" == "${PREV:0:7}" ] && fn_expire_backup "$FILENAME"
|
||||
fi
|
||||
|
||||
PREV=$BACKUP_DATE
|
||||
done
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -196,8 +196,6 @@ while : ; do
|
||||
CMD="$CMD --numeric-ids"
|
||||
CMD="$CMD --links"
|
||||
CMD="$CMD --hard-links"
|
||||
CMD="$CMD --delete"
|
||||
CMD="$CMD --delete-excluded"
|
||||
CMD="$CMD --one-file-system"
|
||||
CMD="$CMD --archive"
|
||||
CMD="$CMD --itemize-changes"
|
||||
@@ -234,16 +232,10 @@ while : ; do
|
||||
rm -- "$LOG_FILE"
|
||||
|
||||
if [ "$NO_SPACE_LEFT" == "0" ]; then
|
||||
# TODO: -y flag
|
||||
read -p "It looks like there is no space left on the destination. Delete old backup? (Y/n) " yn
|
||||
case $yn in
|
||||
[Nn]* ) exit 0;;
|
||||
esac
|
||||
|
||||
fn_log_warn "No space left on device - removing oldest backup and resuming."
|
||||
|
||||
BACKUP_FOLDER_COUNT=$(fn_find_backups | wc -l)
|
||||
if [ "$BACKUP_FOLDER_COUNT" -lt "2" ]; then
|
||||
if [[ "$BACKUP_FOLDER_COUNT" -lt "2" ]]; then
|
||||
fn_log_error "No space left on device, and no old backup to delete."
|
||||
exit 1
|
||||
fi
|
||||
@@ -272,7 +264,7 @@ while : ; do
|
||||
rm -rf -- "$DEST_FOLDER/latest"
|
||||
ln -vs -- "$NOW" "$DEST_FOLDER/latest"
|
||||
|
||||
rm -- "$INPROGRESS_FILE"
|
||||
rm -f -- "$INPROGRESS_FILE"
|
||||
# TODO: grep for "^rsync error:.*$" in log
|
||||
fn_log_info "Backup completed without errors."
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user