Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backups: Add option to disable file revisioning #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=()

# Load config file
[ -f "$CFG_FILE" ] && . "$CFG_FILE"
Expand Down Expand Up @@ -83,6 +85,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 @@ -104,6 +112,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 @@ -131,7 +154,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