From 9233ab3fb3ecfafcabd2d48bcacf7c1e6d20d05d Mon Sep 17 00:00:00 2001 From: Andrew Chadwick Date: Wed, 8 May 2013 16:29:40 +0100 Subject: [PATCH 1/3] config template: documentation updates Make the template a little clearer. SSH commands are for connecting to remote hosts, not the remote hosts+path combination going by $REMOTE in the main script. Bitpocket is handy for syncing music players and flash sticks, so hint at some good flags to use with FAT filesystems. --- bin/bitpocket | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/bitpocket b/bin/bitpocket index 924f43a..2d410a7 100755 --- a/bin/bitpocket +++ b/bin/bitpocket @@ -77,12 +77,15 @@ function init { REMOTE_HOST=$1 REMOTE_PATH="$2" -## SSH command with options for connecting to \$REMOTE +## SSH command with options for connecting to \$REMOTE_HOST # RSYNC_RSH="ssh -p 22 -i $DOT_DIR/id_rsa" ## Uncomment following line to follow symlinks (transform it into referent file/dir) # RSYNC_OPTS="-L" +## Use the following if a FAT or VFAT filesystem is being synchronized +# RSYNC_OPTS="--no-perms --no-owner --no-group --modify-window=2" + ## Uncomment following lines to get sync notifications # SLOW_SYNC_TIME=10 # SLOW_SYNC_START_CMD="notify-send 'BitPocket sync in progress...'" From 55cae8050b7b981397746598ab4654cc51d9ec88 Mon Sep 17 00:00:00 2001 From: Andrew Chadwick Date: Wed, 8 May 2013 16:30:21 +0100 Subject: [PATCH 2/3] sh: permit REMOTE_PATHs with spaces Allow $REMOTE_PATH to contain spaces (hosts too, I guess). Make an error message quote $REMOTE too, for a little more clarity when there are spaces in the path. --- bin/bitpocket | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/bitpocket b/bin/bitpocket index 2d410a7..7e46018 100755 --- a/bin/bitpocket +++ b/bin/bitpocket @@ -138,7 +138,7 @@ function sync { # copies of any local files to be deleted or overwritten. # Order of includes/excludes/filters is EXTREMELY important rsync --dry-run \ - -auvzxi --delete $RSYNC_OPTS --exclude "/$DOT_DIR" --exclude-from "$TMP_DIR/fetch-exclude" $USER_RULES $REMOTE/ . \ + -auvzxi --delete $RSYNC_OPTS --exclude "/$DOT_DIR" --exclude-from "$TMP_DIR/fetch-exclude" $USER_RULES "$REMOTE/" . \ | grep "^[ch<>\.\*][f]\|\*deleting" | sed "s:^\S*\s*::" | sed "s:\(.*\):if [ -f \"\1\" ]; then cp --parents \"\1\" $DOT_DIR/backups/$TIMESTAMP; fi:" | sh || die "BACKUP" [ "$(ls -A $DOT_DIR/backups/$TIMESTAMP)" ] && echo " | Some files were backed up to $DOT_DIR/backups/$TIMESTAMP" [ "$(ls -A $DOT_DIR/backups/$TIMESTAMP)" ] || rmdir $DOT_DIR/backups/$TIMESTAMP @@ -148,14 +148,14 @@ function sync { # Order of includes/excludes/filters is EXTREMELY important echo echo "# Pulling changes from server" - rsync -auvzxi --delete $RSYNC_OPTS --exclude "/$DOT_DIR" --exclude-from "$TMP_DIR/fetch-exclude" $USER_RULES $REMOTE/ . | sed "s/^/ | /" || die "PULL" + rsync -auvzxi --delete $RSYNC_OPTS --exclude "/$DOT_DIR" --exclude-from "$TMP_DIR/fetch-exclude" $USER_RULES "$REMOTE/" . | sed "s/^/ | /" || die "PULL" # Actual push # Send new and updated, remotely remove files deleted locally # Order of includes/excludes/filters is EXTREMELY important echo echo "# Pushing changes to server" - rsync -auvzxi --delete $RSYNC_OPTS --exclude "/$DOT_DIR" $USER_RULES . $REMOTE/ | sed "s/^/ | /" || die "PUSH" + rsync -auvzxi --delete $RSYNC_OPTS --exclude "/$DOT_DIR" $USER_RULES . "$REMOTE/" | sed "s/^/ | /" || die "PUSH" # Save after-sync state # Must be done with rsync itself (rather than find) to respect includes/excludes @@ -296,7 +296,7 @@ function acquire_remote_lock { $REMOTE_RUNNER "mkdir -p \"$REMOTE_TMP_DIR\"; cd \"$REMOTE_PATH\" && mkdir \"$LOCK_DIR\" 2>/dev/null" if [[ $? != 0 ]]; then - echo "Couldn't acquire remote lock. Another client is syncing with $REMOTE or lock file couldn't be created. Exiting." + echo "Couldn't acquire remote lock. Another client is syncing with \"$REMOTE\" or lock file couldn't be created. Exiting." release_lock exit 3 fi From 1b400adc8156e21c5e66c862ce911133468bec46 Mon Sep 17 00:00:00 2001 From: Andrew Chadwick Date: Wed, 8 May 2013 17:03:19 +0100 Subject: [PATCH 3/3] init: permit an empty hostname Allow init to be passed an empty hostname argument. The config file allows it already, referring to local file access for the remote end. Update usage instructions accordingly. --- bin/bitpocket | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/bitpocket b/bin/bitpocket index 7e46018..ffa1da2 100755 --- a/bin/bitpocket +++ b/bin/bitpocket @@ -65,8 +65,8 @@ function init { exit 128 fi - if [[ $# != 2 ]]; then - echo "usage: bitpocket init " + if [[ -z "$2" || -n "$3" ]]; then + echo "usage: bitpocket init { | \"\"} " exit 128 fi @@ -343,7 +343,8 @@ function list { } function usage { - echo "usage: bitpocket [sync|help|pack|log|cron|list|init ]" + echo "usage: bitpocket [sync | help | pack | log | cron | list]" + echo " bitpocket init { | \"\"} " echo "" echo "Available commands:" echo " sync Run the sync process. If no command is specified, sync is run by default." @@ -362,7 +363,7 @@ function usage { if [ "$1" = "init" ]; then # Initialize bitpocket directory - init $2 $3 $4 + init "$2" "$3" "$4" elif [ "$1" = "pack" ]; then # Pack backups using git pack