From 4bb58faeeb2ce70c0aa3f3bf1d49a7096bd04f74 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 25 Nov 2017 12:44:33 +0100 Subject: [PATCH] refactor restore-einfach --- restore-einfach | 79 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/restore-einfach b/restore-einfach index 6ef7bff..b8d0bac 100755 --- a/restore-einfach +++ b/restore-einfach @@ -1,30 +1,57 @@ #!/bin/bash -sicherungspfad="/images/backup" -sicherungsordner="einfach-sicherung" - -while getopts "r:p:" optname; do - case "$optname" in - "r") - rechner="$OPTARG" - ;; - "p") - pfad="$OPTARG" - ;; - esac -done - -if [ -z "$rechner" ] || [ -z "$pfad" ]; then - printf "Es fehlen Parameter!\n" - exit 1 -fi - -printf "################################################################\n" -printf "Daten werden wiederhergestellt\n\n" -printf "Pfad: %s\n" $pfad -printf "Rechner: %s\n" $rechner -printf "################################################################\n" - -rsync --archive --verbose --sparse --acls --hard-links --human-readable --log-file $sicherungspfad/restore-einfach-$(date +%Y-%m-%d).log $sicherungspfad/$sicherungsordner/$rechner/$pfad root@$rechner:$pfad +SetDefaultVariables() { + sicherungspfad="/images/backup" + sicherungsordner="einfach-sicherung" +} + +ReadArguments() { + while getopts "r:p:" optname; do + case "$optname" in + "r") + rechner="$OPTARG" + ;; + "p") + pfad="$OPTARG" + ;; + esac + done + + if [ -z "$rechner" ] || [ -z "$pfad" ]; then + printf "Es fehlen Parameter!\n" + exit 1 + fi +} + +printfStripLine() { + printf "####################" + printf "####################" + printf "####################" + printf "####################\n" +} + +RestoreData() { + remoteLogin="root@$rechner" + fullPathSicherungsOrnder="$sicherungspfad/$sicherungsordner" + + printfStripLine + printf "Daten werden wiederhergestellt\n\n" + printf "Pfad: %s\n" $pfad + printf "Rechner: %s\n" $rechner + printfStripLine + + rsync --archive --verbose --sparse --acls --hard-links --human-readable \ + --log-file $sicherungspfad/restore-einfach-$(date +%Y-%m-%d).log \ + $fullPathSicherungsOrdner/$rechner/$pfad \ + $remoteLogin:$pfad +} + +main() { + SetDefaultVariables + ReadArguments $* + RestoreData +} + +main $* exit 0 -- 2.39.5