]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
refactor restore
authorBastian Dehn <hhaalo@arcor.de>
Sat, 25 Nov 2017 11:37:29 +0000 (12:37 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 25 Nov 2017 11:50:13 +0000 (12:50 +0100)
restore

diff --git a/restore b/restore
index 4399b4adc0111f5abd6f44d073535fd183f6acb1..21852a630290109bfdad3628a2a9d8f40dbc4311 100755 (executable)
--- a/restore
+++ b/restore
@@ -1,35 +1,62 @@
 #!/bin/bash
 
-sicherungspfad="/images/backup"
-sicherungsname="sicherung"
-
-while getopts "d:r:p:" optname; do
-       case "$optname" in
-       "d")
-               datum="$OPTARG"
-               ;;
-       "r")
-               rechner="$OPTARG"
-               ;;
-       "p")
-               pfad="$OPTARG"
-               ;;
-       esac
-done
-
-if [ -z "$datum" ] || [ -z "$rechner" ] || [ -z "$pfad" ]; then
-       printf "Es fehlen Parameter!\n"
-       exit 1
-fi
-
-sicherungsordner="$datum"_"$sicherungsname"
-printf "################################################################\n"
-printf "Daten werden wiederhergestellt\n\n"
-printf "Pfad: %s\n" $pfad
-printf "Rechner: %s\n\n" $rechner
-printf "von der Sicherung vom %s\n" $datum
-printf "################################################################\n"
-
-rsync --archive --verbose --sparse --acls --hard-links --human-readable --log-file $sicherungspfad/restore-$(date +%Y-%m-%d).log $sicherungspfad/$sicherungsordner/$rechner/$pfad root@$rechner:$pfad
+SetDefaultVariables() {
+       sicherungspfad="/images/backup"
+       sicherungsname="sicherung"
+}
+
+ReadArguments() {
+       while getopts "d:r:p:" optname; do
+               case "$optname" in
+               "d")
+                       datum="$OPTARG"
+                       ;;
+               "r")
+                       rechner="$OPTARG"
+                       ;;
+               "p")
+                       pfad="$OPTARG"
+                       ;;
+               esac
+       done
+
+       if [ -z "$datum" ] || [ -z "$rechner" ] || [ -z "$pfad" ]; then
+               printf "Es fehlen Parameter!\n"
+               exit 1
+       fi
+}
+
+printfStripLine() {
+       printf "####################"
+       printf "####################"
+       printf "####################"
+       printf "####################\n"
+}
+
+RestoreData() {
+       remoteLogin="root@$rechner"
+       sicherungsordner="$datum"_"$sicherungsname"
+       fullPathSicherungsOrnder="$sicherungspfad/$sicherungsordner"
+
+       printfStripLine
+       printf "Daten werden wiederhergestellt\n\n"
+       printf "Pfad: %s\n" $pfad
+       printf "Rechner: %s\n\n" $rechner
+       printf "von der Sicherung vom %s\n" $datum
+       printfStripLine
+
+       rsync --archive --verbose --sparse --acls --hard-links --human-readable \
+               --log-file $sicherungspfad/restore-$(date +%Y-%m-%d).log \
+               $fullPathSicherungsordner/$rechner/$pfad \
+               $remoteLogin:$pfad
+}
+
+main() {
+       SetDefaultVariables
+       ReadArguments $*
+       RestoreData
+}
+
+main $*
 
 exit 0