Rebase on master.
This commit is contained in:
@@ -40,12 +40,10 @@ An optional exclude file can be provided as a third parameter. It should be comp
|
|||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
* Check if there's enough space in the destination before doing the backup. Also automatically delete old backups.
|
* Minor changes (see TODO comments in the source).
|
||||||
|
|
||||||
# LICENSE
|
# LICENSE
|
||||||
|
|
||||||
[MIT](http://opensource.org/licenses/MIT)
|
[MIT](http://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
|
||||||
[](https://bitdeli.com/free "Bitdeli Badge")
|
[](https://bitdeli.com/free "Bitdeli Badge")
|
||||||
|
|
||||||
|
|||||||
+11
-15
@@ -78,13 +78,12 @@ fi
|
|||||||
# Setup additional variables
|
# Setup additional variables
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BACKUP_FOLDER_PATTERN="^[[:digit:]][[:digit:]][[:digit:]][[:digit:]]-[[:digit:]][[:digit:]]-[[:digit:]][[:digit:]]-[[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]][[:digit:]]$"
|
BACKUP_FOLDER_PATTERN=????-??-??-??????
|
||||||
NOW=$(date +"%Y-%m-%d-%H%M%S")
|
NOW=$(date +"%Y-%m-%d-%H%M%S")
|
||||||
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
|
||||||
LAST_TIME=$(ls -1 -- "$DEST_FOLDER" | grep "$BACKUP_FOLDER_PATTERN" | tail -n 1)
|
PREVIOUS_DEST=$(find "$DEST_FOLDER" -type d -name "$BACKUP_FOLDER_PATTERN" -prune | sort | tail -n 1)
|
||||||
PREVIOUS_DEST=$DEST_FOLDER/$LAST_TIME
|
|
||||||
INPROGRESS_FILE=$DEST_FOLDER/backup.inprogress
|
INPROGRESS_FILE=$DEST_FOLDER/backup.inprogress
|
||||||
KEEP_ALL_DATE=$(date -d '-1 day' +%s)
|
KEEP_ALL_DATE=$(date -d '-1 day' +%s)
|
||||||
KEEP_DAILIES_DATE=$(date -d '-1 month' +%s)
|
KEEP_DAILIES_DATE=$(date -d '-1 month' +%s)
|
||||||
@@ -103,19 +102,18 @@ fi
|
|||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
if [ -f "$INPROGRESS_FILE" ]; then
|
if [ -f "$INPROGRESS_FILE" ]; then
|
||||||
if [ "$LAST_TIME" != "" ]; then
|
if [ "$PREVIOUS_DEST" != "" ]; 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=$(ls -1 -- "$DEST_FOLDER" | grep "$BACKUP_FOLDER_PATTERN" | tail -n 2 | wc -l)
|
LINE_COUNT=$(find "$DEST_FOLDER" -type d -name "$BACKUP_FOLDER_PATTERN" -prune | 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 "$BACKUP_FOLDER_PATTERN" | tail -n 2 | head -n 1)
|
PREVIOUS_PREVIOUS_DEST=$(find "$DEST_FOLDER" -type d -name "$BACKUP_FOLDER_PATTERN" -prune | sort | tail -n 2 | head -n 1)
|
||||||
LAST_TIME=$SECOND_LAST_TIME
|
PREVIOUS_DEST=$PREVIOUS_PREVIOUS_DEST
|
||||||
else
|
else
|
||||||
LAST_TIME=""
|
PREVIOUS_DEST=""
|
||||||
fi
|
fi
|
||||||
PREVIOUS_DEST=$DEST_FOLDER/$LAST_TIME
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -127,7 +125,7 @@ while [ "1" ]; do
|
|||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
LINK_DEST_OPTION=""
|
LINK_DEST_OPTION=""
|
||||||
if [ "$LAST_TIME" == "" ]; then
|
if [ "$PREVIOUS_DEST" == "" ]; then
|
||||||
fn_log_info "No previous backup - creating new one."
|
fn_log_info "No previous backup - creating new one."
|
||||||
else
|
else
|
||||||
# If the path is relative, it needs to be relative to the destination. To keep
|
# If the path is relative, it needs to be relative to the destination. To keep
|
||||||
@@ -233,20 +231,18 @@ while [ "1" ]; do
|
|||||||
|
|
||||||
fn_log_warn "No space left on device - removing oldest backup and resuming."
|
fn_log_warn "No space left on device - removing oldest backup and resuming."
|
||||||
|
|
||||||
BACKUP_FOLDER_COUNT=$(ls -1 $DEST_FOLDER | grep "$BACKUP_FOLDER_PATTERN" | wc -l)
|
BACKUP_FOLDER_COUNT=$(find "$DEST_FOLDER" -type d -name "$BACKUP_FOLDER_PATTERN" -prune | 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."
|
fn_log_error "No space left on device, and no old backup to delete."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OLDEST_BACKUP=$(ls -1 $DEST_FOLDER | grep "$BACKUP_FOLDER_PATTERN" | head -n 1)
|
OLD_BACKUP_PATH=$(find "$DEST_FOLDER" -type d -name "$BACKUP_FOLDER_PATTERN" -prune | head -n 1)
|
||||||
if [ "$OLDEST_BACKUP" == "" ]; 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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OLD_BACKUP_PATH="$DEST_FOLDER/$OLDEST_BACKUP"
|
|
||||||
|
|
||||||
# Double-check that we're on a backup destination to be completely sure we're deleting the right folder
|
# Double-check that we're on a backup destination to be completely sure we're deleting the right folder
|
||||||
OLD_BACKUP_PARENT_PATH=$(dirname -- "$OLD_BACKUP_PATH")
|
OLD_BACKUP_PARENT_PATH=$(dirname -- "$OLD_BACKUP_PATH")
|
||||||
if [ "$(fn_is_backup_destination $OLD_BACKUP_PARENT_PATH)" != "1" ]; then
|
if [ "$(fn_is_backup_destination $OLD_BACKUP_PARENT_PATH)" != "1" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user