summaryrefslogtreecommitdiff
path: root/rsync_tmbackup.sh
diff options
context:
space:
mode:
authorRobert Bruce Park <r@robru.ca>2013-11-26 13:11:00 -0800
committerRobert Bruce Park <r@robru.ca>2013-11-26 13:11:00 -0800
commite7fc37076c9f17f22966dc3fdf3eb2aa6cafa4fe (patch)
treec9c9dbb2c39da24e8ea0abf48fe046c4a64291c1 /rsync_tmbackup.sh
parent4720f404afc1ddded26a7b40a68b5289cc05d3b0 (diff)
parent2e413d82d7b19da06b7f7ed902e052fb7875e56e (diff)
Rebase on @laurent22/master.
Diffstat (limited to 'rsync_tmbackup.sh')
-rw-r--r--rsync_tmbackup.sh48
1 files changed, 20 insertions, 28 deletions
diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh
index be4c982..8e94931 100644
--- a/rsync_tmbackup.sh
+++ b/rsync_tmbackup.sh
@@ -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
+ if [ -z "$TIMESTAMP" ]; then
+ fn_log_warn "Could not parse date: $FILENAME"
+ continue
+ fi
- elif [ $stamp -ge $KEEP_DAILIES_DATE ]; then
+ if [ $TIMESTAMP -ge $KEEP_ALL_DATE ]; then
+ true
+ elif [ $TIMESTAMP -ge $KEEP_DAILIES_DATE ]; then
# Delete all but the most recent of each day.
- [ "${date:0:10}" == "${prev:0:10}" ] && fn_expire_backup "$fname"
-
+ [ "${BACKUP_DATE:0:10}" == "${PREV:0:10}" ] && fn_expire_backup "$FILENAME"
else
# Delete all but the most recent of each month.
- [ "${date:0:7}" == "${prev:0:7}" ] && fn_expire_backup "$fname"
+ [ "${BACKUP_DATE:0:7}" == "${PREV:0:7}" ] && fn_expire_backup "$FILENAME"
fi
- prev=$date
+ 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