#!/bin/bash # # entrypoint for all actions # VER="2.1.4" HERE=$(dirname "$0") THIS_SCRIPT=$0 show_help() { echo "Server Backup $VER" echo "usage: $0 options" echo " -d, --daily start daily backup on local machine" echo " -w, --weekly start weekly backup on local machine" echo " -e, --export export backups to USB-HDD" echo " -l, --list list archives" echo ' -c, --content ' echo " show contents of archive (path from $NAS_ROOT)" echo ' -r, --restore ' echo " restore files from archive to $RESTORE_PATH" echo " -h, -?. --help show this help" echo " " echo " -d, -w, -e must be run as superuser." echo " " } 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 101 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 102 fi file= archive= while :; do case $1 in -h|-\?|--help) show_help # Display a usage synopsis. exit 0 ;; -d|--daily) MAIL_LOG_FILE="${log_file_name}.auto.log" check_root backup_daily break ;; -w|--weekly) MAIL_LOG_FILE="${log_file_name}.auto.log" check_root backup_weekly break ;; -e|--export) MAIL_LOG_FILE="${log_file_name}.auto.log" check_root export_backups break ;; -l|--list) list_archives break; ;; -c|--content) if [ "$2" ]; then list_archive_content "$2" else echo 'ERROR: "--content" requires the archive name as an argument.' echo show_help fi break ;; -r|--restore) if [ "$2" ]; then archive=$2 shift 2 restore "$archive" "$@" else echo 'ERROR: "--restore" requires at least the archive name as an argument.' echo show_help fi break ;; --rx) MAIL_LOG_FILE="${log_file_name}.auto.log" check_root shift do_restore $@ break ;; --) # 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