Skip to content

Commit

Permalink
backups: Add option to disable file revisioning
Browse files Browse the repository at this point in the history
Also, add a BACKUP_EXCLUDE list which is a list of wildcard patterns which can
be used to exclude certain files from backup revisioning. This is useful for
temporary files such as those used for locks and undo space.
  • Loading branch information
Jared Hancock committed Aug 3, 2017
1 parent 9113567 commit 13a0282
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion bin/bitpocket
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ LOCK_DIR="$TMP_DIR/lock" # Use a lock directory for atomic locks. See the Bash
SLOW_SYNC_TIME=10
SLOW_SYNC_FILE="$TMP_DIR/slow"
RSYNC_RSH="ssh"
BACKUPS=true
BACKUP_EXCLUDE=()

# Default command-line options and such
COMMANDS=()
Expand Down Expand Up @@ -90,6 +92,12 @@ function init {
REMOTE_HOST=$1
REMOTE_PATH="$2"
## Enable file revisioning (>false< to disable)
BACKUPS=true
# These files are *not* revisioned. These use bash wildcard patterns instead of
# rsync filter patterns
BACKUP_EXCLUDE=( '*.tmp' '*.temp' '~\$*' '*.TMP' )
## SSH command with options for connecting to \$REMOTE
# RSYNC_RSH="ssh -p 22 -i $DOT_DIR/id_rsa"
Expand All @@ -111,6 +119,21 @@ function log {
tail -f "$DOT_DIR/log"
}

function should_backup() {
# Ensure backups are enabled, this is a file (not a dir or link), and that
# the file exists locally
[[ $BACKUPS && -f "$1" ]] || return 1

# Handle backup exclusions
for ex in "${BACKUP_EXCLUDE[@]}"
do
[[ "$1" == $ex ]] && return 1
[[ $(basename "$1") == $ex ]] && return 1
done

return 0
}

function pull() {
# Actual fetch
# Pulling changes from server
Expand Down Expand Up @@ -138,7 +161,7 @@ function pull() {
filename=$(sed "s:^\S*\s*::" <<< "$line" | sed 's:\d96:\\\`:g')
if [[ "$line" =~ ^[ch\<\>][fd]|^\*deleting ]]; then
operation=${line%% *}
if [[ -f "$filename" ]]; then
if should_backup "$filename"; then
[[ -d "$DOT_DIR"/backups/$TIMESTAMP ]] \
|| mkdir -p "$DOT_DIR"/backups/$TIMESTAMP
cp --parents -p --reflink=auto "$filename" \
Expand Down

0 comments on commit 13a0282

Please sign in to comment.