From 18258ad2a9eaf8b958978b8ec8a39b6b99032388 Mon Sep 17 00:00:00 2001 From: Bhuvanesh Kumar Date: Wed, 29 Jan 2014 00:18:38 +0530 Subject: [PATCH 1/4] display usage info if required args not passed --- rsync_tmbackup.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index e5192bd..2e83f5a 100755 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -24,6 +24,9 @@ trap 'fn_terminate_script' SIGINT # ----------------------------------------------------------------------------- # Small utility functions for reducing code duplication # ----------------------------------------------------------------------------- +fn_display_usage() { + fn_log_info "Usage : $(basename $0) [exclude-pattern file]" +} fn_parse_date() { # Converts YYYY-MM-DD-HHMMSS to YYYY-MM-DD HH:MM:SS and then to Unix Epoch. @@ -53,6 +56,11 @@ fn_expire_backup() { # ----------------------------------------------------------------------------- # Source and destination information # ----------------------------------------------------------------------------- +#display usage information if required arguments are not passed +if [[ "${#@}" -lt 2 ]]; then + fn_display_usage + exit 1 +fi SRC_FOLDER="${1%/}" DEST_FOLDER="${2%/}" From 9bc6be475a03a9ac4a119b3035a8e0208efb8e7d Mon Sep 17 00:00:00 2001 From: Bhuvanesh Kumar Date: Thu, 30 Jan 2014 23:13:30 +0530 Subject: [PATCH 2/4] if destination is not specified assume current folder --- rsync_tmbackup.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index 2e83f5a..11ccdd7 100755 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -25,7 +25,7 @@ trap 'fn_terminate_script' SIGINT # Small utility functions for reducing code duplication # ----------------------------------------------------------------------------- fn_display_usage() { - fn_log_info "Usage : $(basename $0) [exclude-pattern file]" + fn_log_info "Usage : $(basename $0) [destination] [exclude-pattern file]" } fn_parse_date() { @@ -57,13 +57,19 @@ fn_expire_backup() { # Source and destination information # ----------------------------------------------------------------------------- #display usage information if required arguments are not passed -if [[ "${#@}" -lt 2 ]]; then +if [[ "${#@}" -lt 1 ]]; then fn_display_usage exit 1 fi SRC_FOLDER="${1%/}" -DEST_FOLDER="${2%/}" +#if destination folder is not specified assume current folder +if [ -z ${2} ]; then + DEST_FOLDER="." + echo ${2} +else + DEST_FOLDER="${2%/}" +fi EXCLUSION_FILE="$3" for ARG in "$SRC_FOLDER" "$DEST_FOLDER" "$EXCLUSION_FILE"; do From 6e27f773161bdf62979f3833138b0792634c6162 Mon Sep 17 00:00:00 2001 From: Bhuvanesh Kumar Date: Tue, 8 Dec 2015 00:32:10 +0530 Subject: [PATCH 3/4] Add backup files(*~) to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e8d64cc..aa54d41 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea -test.sh \ No newline at end of file +test.sh +*~ From a8504cbf4cfee7978b57277ff0c1f8735d27c16d Mon Sep 17 00:00:00 2001 From: Bhuvanesh Kumar Date: Wed, 3 Feb 2016 21:38:17 +0530 Subject: [PATCH 4/4] modified to not assume destination if not provided --- rsync_tmbackup.sh | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index a5dd28d..2d67694 100755 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -32,7 +32,7 @@ trap 'fn_terminate_script' SIGINT # Small utility functions for reducing code duplication # ----------------------------------------------------------------------------- fn_display_usage() { - fn_log_info "Usage : $(basename $0) [[[user@host:]destination] exclude-pattern-file]" + fn_log_info "Usage : $(basename $0) <[user@host:]destination> [exclude-pattern-file]" } fn_parse_date() { @@ -114,18 +114,12 @@ SSH_CMD="" SSH_FOLDER_PREFIX="" #display usage information if required arguments are not passed -if [[ "${#@}" -lt 1 ]]; then +if [[ "${#@}" -lt 2 ]]; then fn_display_usage exit 1 fi SRC_FOLDER="${1%/}" - -#if destination folder is not specified assume current folder -if [ -z ${2} ]; then - DEST_FOLDER="." -else - DEST_FOLDER="${2%/}" -fi +DEST_FOLDER="${2%/}" EXCLUSION_FILE="$3" fn_parse_ssh