#!/bin/bash # # entrypoint for all actions # VER="2.0.0" 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 " " } # # Script muss unter root bzw. sudo laufen, sonst gibt es jede Menge Probleme # mit Zugriff auf die diversen Verzeichnisse. # if [ "$(id -u)" -ne 0 ]; then echo "**" echo "** ERROR: script has to be run as superuser!" echo "**" exit 100 fi HERE=$(dirname "$0") THIS_SCRIPT=$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 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 log_file_name="$(realpath $HERE/../../../log/backup/$HOST_NAME-$(date '+%Y-%m-%d_%H%M'))" LOG_FILE="${log_file_name}.log" 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" backup_daily break ;; -w|--weekly) MAIL_LOG_FILE="${log_file_name}.auto.log" backup_weekly break ;; -e|--export) MAIL_LOG_FILE="${log_file_name}.auto.log" export_backups 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 ;; --) # 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