Files
server-backup/test/main.sh
T

89 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
show_help() {
echo "usage: $0 options"
echo " -a, --auto start nightly backup"
echo " -l, --list list archives"
echo ' -c, --content <archive> '
echo " show contents of archive"
echo ' -r, --restore <archive> <file(s)> '
echo " restore files from archive to pwd"
echo " -h, -?. --help show this help"
}
echo " ### main.sh"
# Initialize all the option variables.
# This ensures we are not contaminated by variables from the environment.
file=
archive=
while :; do
case $1 in
-h|-\?|--help)
show_help # Display a usage synopsis.
exit 0
;;
-a|--auto)
shift
. $HERE/$HOST_NAME.sh "$@" >$LOGF 2>&1
break # exit kehrt nicht zu run.sh zurück
;;
-l|--list)
. $HERE/$HOST_NAME.sh -l
break;
;;
-c|--content)
if [ "$2" ]; then
echo "not yet implemented"
#. $HERE/$HOST_NAME.sh -c $2
else
echo 'ERROR: "--content" requires a non-empty option argument.'
fi
break
;;
-r|--restore)
if [ "$2" ]; then
echo "not yet implemented"
archive=$2
shift
#. $HERE/$HOST_NAME.sh -r $archive $@
else
echo 'ERROR: "--restore" requires a non-empty option argument.'
fi
break
;;
# --- example -> https://mywiki.wooledge.org/BashFAQ/035
-f|--file) # Takes an option argument; ensure it has been specified.
if [ "$2" ]; then
file=$2
shift
else
die 'ERROR: "--file" requires a non-empty option argument.'
fi
;;
--file=?*)
file=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--file=) # Handle the case of an empty --file=
die 'ERROR: "--file" requires a non-empty option argument.'
;;
--) # End of all options.
shift
break
;;
-?*)
echo "WARN: Unknown option (ignored): $1"
echo
show_help
exit
;;
*) # Default case: No more options, so break out of the loop.
break
esac
shift
done