]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
change: optimize VM backup reduce redundant code
authorBastian Dehn <hhaalo@arcor.de>
Sun, 26 Nov 2017 10:16:50 +0000 (11:16 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 26 Nov 2017 10:16:50 +0000 (11:16 +0100)
backup

diff --git a/backup b/backup
index 50e06799f1fc7f9adb2775815900ce6672b0f7c8..34262f0f1247d3f266c7b1456e7bd29fe7008173 100755 (executable)
--- a/backup
+++ b/backup
@@ -58,6 +58,9 @@ printfStripLine() {
 ################################################################################
 
 BackupVMDiscs() {
+       local readonly Disks=$(ssh $remoteLogin virsh domblklist $VM --details \
+               | grep disk \
+               | awk '{print $4}')
        local readonly logFile="$backRemotePCPath/backup-$(echo $Disk \
                | sed 's/\//-/g').log"
 
@@ -84,13 +87,8 @@ BackupOnlineVMs() {
                printfStripLine
                printf "Rechner %s; %s ist online\n" "$remoterechner" "$VM"
                printf "Fahre %s herunter\n\n" "$VM"
-
                ssh $remoteLogin virsh shutdown $VM | WaitVMShutdown
-               Disks=$(ssh $remoteLogin virsh domblklist $VM --details \
-                               | grep disk \
-                               | awk '{print $4}')
                BackupVMDiscs
-
                printf "\nFahre %s hoch\n" "$VM"
                ssh $remoteLogin virsh start $VM
                printfStripLine
@@ -105,10 +103,6 @@ BackupOfflineVMs() {
        for VM in $offlineVM; do
                printfStripLine
                printf "Rechner %s; %s ist offline\n\n" "$remoterechner" "$VM"
-
-               Disks=$(ssh $remoteLogin virsh domblklist $VM --details \
-                       | grep disk \
-                       | awk '{print $4}')
                BackupVMDiscs
                printfStripLine
        done