From e092d5c2fd20cf6975efa44aff3af15adcdbe7d9 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Fri, 15 Nov 2013 18:06:49 +0800 Subject: Updated list of features in README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e36e090..b5c2c78 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,9 @@ An optional exclude file can be provided as a third parameter. It should be comp * Exclude file - support for pattern-based exclusion via the `--exclude-from` rsync parameter. -* The application is one bash script that can be easily edited. +* "latest" symlink that points to the latest successful backup. + +* The application is just one bash script that can be easily edited. # TODO -- cgit v1.2.3 From d31b689f6be4bdc46eaeb0ed1b6e39b09a4d06d5 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 16 Nov 2013 22:50:10 +0800 Subject: Removed old backup deletion prompt, and formatting tweaks. - Removed old backup deletion prompt as it's not really needed. - Made all variables uppercase for consistency. - Used double square brackets in `if` statements. --- README.md | 4 ++++ rsync_tmbackup.sh | 44 +++++++++++++++++++------------------------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index a138c35..bf29d25 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ An optional exclude file can be provided as a third parameter. It should be comp * Exclude file - support for pattern-based exclusion via the `--exclude-from` rsync parameter. +* Automatically purge old backups - within 24 hours, all backups are kept. Within one month, the most recent backup for each day is kept. For all previous backups, the most recent of each month is kept. + * "latest" symlink that points to the latest successful backup. * The application is just one bash script that can be easily edited. @@ -44,6 +46,8 @@ An optional exclude file can be provided as a third parameter. It should be comp * Minor changes (see TODO comments in the source). +* Backup to remote drive? + # LICENSE [MIT](http://opensource.org/licenses/MIT) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index 8b2a0e1..d573374 100644 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -63,8 +63,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 @@ -103,7 +103,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/.rsync_tmbackup" LOG_FILE="$PROFILE_FOLDER/$NOW.log" @@ -144,7 +143,7 @@ fi while [ "1" ]; 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="" @@ -171,28 +170,29 @@ while [ "1" ]; 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 | sort -r); 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 [ -z "$TIMESTAMP" ]; then + fn_log_warn "Could not parse date: $FILENAME" + continue + fi - if [ $stamp -ge $KEEP_ALL_DATE ]; then + if [ $TIMESTAMP -ge $KEEP_ALL_DATE ]; then true - - elif [ $stamp -ge $KEEP_DAILIES_DATE ]; then + 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 # ----------------------------------------------------------------------------- @@ -248,22 +248,16 @@ while [ "1" ]; 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 OLD_BACKUP_PATH=$(fn_find_backups | head -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." exit 1 fi -- cgit v1.2.3 From b8fb75bbc071cc2ed05fd393834ef186e220d6eb Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 24 Nov 2013 17:23:00 +0800 Subject: Removed dangerous and unneeded delete flags. Since there's normally nothing in the destination directory, the delete flags are not really needed. --- rsync_tmbackup.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index d573374..97fd6a5 100644 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -210,8 +210,6 @@ while [ "1" ]; 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" -- cgit v1.2.3 From 928b32f83ea3cff1ac8c4ddf9088cac97b651bab Mon Sep 17 00:00:00 2001 From: Eric Fournie Date: Mon, 25 Nov 2013 14:47:18 +0000 Subject: Force deleting INPROGRESS_FILE (avoids waiting for user input if rm is aliased to rm -i) --- rsync_tmbackup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index d573374..2beca81 100644 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -282,7 +282,7 @@ while [ "1" ]; do ln -s -- $(basename -- "$DEST") "latest" cd - - rm -- "$INPROGRESS_FILE" + rm -f -- "$INPROGRESS_FILE" # TODO: grep for "^rsync error:.*$" in log fn_log_info "Backup completed without errors." exit 0 -- cgit v1.2.3 From cb252f75457fdd1dac8376d275e26a7fe24ce3c7 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 26 Nov 2013 03:40:23 +0800 Subject: Update README.md Mentioned level of testing. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf29d25..1d63c9d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Rsync time backup -Time Machine style backup with rsync. Should work on Linux, Mac OS X and Windows with Cygwin. +Time Machine style backup with rsync. Should work on Linux (tested on some distros), Mac OS X (fully tested) and Windows with Cygwin (not tested yet but feeback would be welcome). # Installation -- cgit v1.2.3