#!/bin/bash # # entrypoint for all actions # show_help() { echo "usage: $0 options" echo " -d, --daily start daily backup on local machine" echo " -w, --weekly start weekly backup on local machine" echo " --list list archives" echo ' --content ' echo " show contents of archive" echo ' -r, --restore ' echo " restore files from archive to pwd" echo " -h, -?. --help show this help" echo " " echo " Script muss auf dem jeweiligen Server ausgeführt werden (ggf. via ssh)." echo " " } HERE=$(dirname "$0") if [ -f $HERE/main.inc.sh ]; then . $HERE/main.inc.sh else echo "**" echo "** ERROR: Datei \"$HERE/main.inc.sh\" nicht gefunden. " echo "** Script wird abgebrochen" echo "**" show_help exit 1 fi if [ -f $HERE/$HOST_NAME.sh ]; then . $HERE/$HOST_NAME.sh else echo "**" echo "** ERROR: Datei \"$HOST_NAME.sh\" nicht gefunden (falscher Rechner?). " echo "** Script wird abgebrochen." echo "**" show_help exit 2 fi LOG_FILE="$NAS_ROOT/log/$LOG_FILE-$(date '+%Y-%m-%d_%H%M').log" file= archive= while :; do case $1 in -h|-\?|--help) show_help # Display a usage synopsis. exit 0 ;; -d|--daily) LOG_FILE=$BACKUP_TARGET/backup.log backup_daily break ;; -w|--weekly) LOG_FILE=$BACKUP_TARGET/backup.log backup_weekly break ;; --list) list_archives "$NAS_ROOT/daily/$HOST_NAME" if [ -d "$NAS_ROOT/weekly/$HOST_NAME" ]; then list_archives "$NAS_ROOT/weekly/$HOST_NAME" fi break; ;; --content) if [ "$2" ]; then list_archive_content "$NAS_ROOT" "$2" else echo 'ERROR: "--content" requires a non-empty option argument.' fi break ;; -r|--restore) if [ "$2" ]; then archive=$2 shift restore "$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 exit 0