If no argument is provided, a list file of the name my_hosts.list will be used (if present).
Options: -v Verbose output.
Options: -q Quiet mode - suppress most output.
-v Verbose output.
-h Show this help.
"
...
...
@@ -33,8 +34,10 @@ VERBOSITY="" ## Define the default verbosity (i.e. none). Can be changed with
DEST="/dev/null"## Default destination for output. Change to /dev/stdout with option -v.
##########Interpret options
while getopts'fvh' OPTION;do## Call getopts to identify selected options and set corresponding flags.
while getopts'qvh' OPTION;do## Call getopts to identify selected options and set corresponding flags.
case"$OPTION"in
q)QUIET_MODE="TRUE"## -q sets flag that will suppress some output otherwise destined for /dev/stdout.
VERBOSITY="-q";;
v)VERBOSITY="-v"## -v activates verbose mode by iadding the -v flag to the bu.sh command.
DEST="/dev/stdout";;
h)echo-e"${USAGE}"## -h option just prints the usage then quits.
...
...
@@ -70,11 +73,11 @@ if [ -e "${TEMP_REM_SYS_LIST}" ]; then rm "${TEMP_REM_SYS_LIST}"; fi ## If it ex
##########Validate the argument and thus define the remote host/s.
## Arg specifies a remote host.
if[!-f"${ARGUMENT}"]||[!-r"${ARGUMENT}"];then## If argument is not (!) a normal file (-f) or (||) in is not (!) readable (-r).
echo-e"\n${BLUE}Remote system is \"${RESET}${ARGUMENT}${BLUE}\".${RESET}"## Then assume provided argument is a single host (either [host] or [user@host]).
if["${QUIET_MODE}"!="TRUE"];then echo-e"\n${BLUE}Remote system is \"${RESET}${ARGUMENT}${BLUE}\".${RESET}";fi## Then assume provided argument is a single host (either [host] or [user@host]).
echo"${ARGUMENT}">"${TEMP_REM_SYS_LIST}"## Create the temp list file which will just contain the single entry.
## Arg specifies a list of remote hosts.
else
echo-e"\n${BLUE}Remote system list is \"${RESET}${ARGUMENT}${BLUE}\".${RESET}"## Tell the user the list looks okay.
if["${QUIET_MODE}"!="TRUE"];then echo-e"\n${BLUE}Remote system list is \"${RESET}${ARGUMENT}${BLUE}\".${RESET}";fi## Tell the user the list looks okay.
while read-r LINE ;do## Iterate for every line in the system list.
STRIPPED_LINE="$(echo"${LINE}" | cut-d"#"-f 1)"## Strip the content of the line after (and including) the first '#'.
if["${STRIPPED_LINE}"];then## If there is anything left in the string (i.e. if entire row is NOT a comment).
echo-E"${REM_SYS}${COLUMN_SPACER}${GREEN}Success.${RESET}">>"${TEMP_BALL_SUMMARY}"## If the above succeeds, record the success.
echo-e"----------------------------------------------------------------------------------"## Note a "success" means the ssh session was created and exited.
if["${QUIET_MODE}"!="TRUE"];then echo-e"----------------------------------------------------------------------------------";fi## Note a "success" means the ssh session was created and exited.
## gracefully. Failures with the called script are not checcked.
file - a specific file/directory to be backed up (requires option \"-f\").
file - a specific file/directory to be backed up (requires option \"-f\" or \"-d\").
list - a text list of files/directories to be backed up.
Valid options:
-f - Argument is a specific file/directory to be backed up.
-d - Argument is a specific file/directory to be backed up.
-f - Argument is a specific file to be backed up.
-d - Argument is a specific directory to be backed up.
-l - Argument is a text file containing a list of file/directories to be backed up.
-q - Quiet - suppress most output.
-v - Verbose - print additional info to stdout.
-h - Print this usage and exit.
none - No option entered - Default assumes \"-l\".
...
...
@@ -42,11 +43,12 @@ Valid options:
DEST="/dev/null"## Default destination for command output. I.e. don't display on screen. -v (verbose) option changes this.
##########Interpret options
while getopts'fdlvh' OPTION;do## Call getopts to identify selected options and set corresponding flags.
while getopts'fdlqvh' OPTION;do## Call getopts to identify selected options and set corresponding flags.
case"$OPTION"in
f)ARGUMENT_TYPE="FILE";;## -f identifies the provided argument as a directory/file to be backed up.
d)ARGUMENT_TYPE="FILE";;## -d identifies the provided argument as a directory/file to be backed up.
l)ARGUMENT_TYPE="LIST";;## -l identifies the argument as a list of files to be backed up.
q)QUIET_MODE="TRUE";;## -q flag to suppress some output that would otherwise go to /dev/stdout.
v)DEST="/dev/stdout";;## -v activates verbose mode by sending output to /dev/stdout (instead of /dev/null).
h)echo-e"$USAGE"## -h option just prints the usage then quits.
exit${SUCCESS}## Exit successfully.
...
...
@@ -167,17 +169,17 @@ fi
##########Run the sync.
echo>${DEST}
if["$RSYNC_INSTALLED"=="TRUE"];then## Use rsync (preferred, dir structure will be retained within backup dir).
echo-e"${BLUE}Using rsync to copy listed files to \"${RESET}${BU_USER}@${BU_SERVER}:${BU_REMOTE_DIR}/${BLUE}\"${RESET}"
if["${QUIET_MODE}"!="TRUE"];then echo-e"${BLUE}Using rsync to copy listed files to \"${RESET}${BU_USER}@${BU_SERVER}:${BU_REMOTE_DIR}/${BLUE}\"${RESET}";fi
else## Use scp (dir structure will not be retained)
echo-e"${BLUE}Using scp to copy listed files to \"${RESET}${BU_USER}@${BU_SERVER}:${BU_REMOTE_DIR}/${BLUE}\"${RESET}"
if["${QUIET_MODE}"!="TRUE"];then echo-e"${BLUE}Using scp to copy listed files to \"${RESET}${BU_USER}@${BU_SERVER}:${BU_REMOTE_DIR}/${BLUE}\"${RESET}";fi
while read-r BU_FILE;do## Must loop to run scp for every entry in list file.