]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
fix: 80 character line length
authorBastian Dehn <hhaalo@arcor.de>
Sat, 25 Nov 2017 16:42:26 +0000 (17:42 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 25 Nov 2017 16:47:02 +0000 (17:47 +0100)
backup
backup-einfach
restore
restore-einfach

diff --git a/backup b/backup
index 829cc6cc535c7665c016086f007ec57faa724d0b..50e06799f1fc7f9adb2775815900ce6672b0f7c8 100755 (executable)
--- a/backup
+++ b/backup
@@ -4,8 +4,8 @@
 ### vorhaerigen Backup
 
 SetDefaultVariables() {
-       sicherungspfad="/images/backup"
-       sicherungsname="sicherung"
+       backpath="/images/backup"
+       backname="sicherung"
        wunschanzahl=20
        mode="incremental"
 }
@@ -24,23 +24,25 @@ ReadArguments() {
 }
 
 CreateBackupFolder() {
-       sicherungsordner="$(date +%Y-%m-%d)"_"$sicherungsname"
-       vorsicherungsordner="$(date -d "1 Day ago" +%Y-%m-%d)"_"$sicherungsname"
-
-       if [ ! -d $sicherungspfad/$vorsicherungsordner ]; then
-               tmpordner=$(find $sicherungspfad -maxdepth 1 -type d \
-                       -name "*_"$sicherungsname"" | sort | tail --lines=1)
-               vorsicherungsordner=${tmpordner##*/}
+       backDir="$(date +%Y-%m-%d)"_"$backname"
+       lastBackDir="$(date -d "1 Day ago" +%Y-%m-%d)"_"$backname"
+
+       if [ ! -d $backpath/$lastBackDir ]; then
+               tmpordner=$(find $backpath -maxdepth 1 -type d \
+                       -name "*_"$backname"" \
+                       | sort \
+                       | tail --lines=1)
+               lastBackDir=${tmpordner##*/}
        fi
 }
 
 CreateBackupFolderRemotePC() {
-       mkdir --parents $sicherungspfad/$sicherungsordner/$remoterechner
+       mkdir --parents $backpath/$backDir/$remoterechner
 }
 
 GetHardLinkOpts() {
        if [ "$mode" == "incremental" ]; then
-               hardlinkopt="--link-dest=$sicherungspfad/$vorsicherungsordner/$remoterechner"
+               hardlinkopt="--link-dest=$backpath/$lastBackDir/$remoterechner"
        fi
 }
 
@@ -56,20 +58,23 @@ printfStripLine() {
 ################################################################################
 
 BackupVMDiscs() {
+       local readonly logFile="$backRemotePCPath/backup-$(echo $Disk \
+               | sed 's/\//-/g').log"
+
        for Disk in $Disks; do
                printf "Disk %s von %s wird gesichert\n\n" "$Disk" "$VM"
-               rsync --archive --verbose --sparse --acls --hard-links --relative \
-                       --progress --human-readable \
-                       --log-file=$backupRemoteRechnerPath/backup-$(echo $Disk | sed 's/\//-/g').log \
+               rsync --archive --verbose --sparse --acls --hard-links \
+                       --relative --progress --human-readable \
+                       --log-file=$logFile \
                        $hardlinkopt \
-                       $remoteLogin:$Disk $backupRemoteRechnerPath
+                       $remoteLogin:$Disk $backRemotePCPath
        done
 }
 
 WaitVMShutdown() {
        while [ "$(ssh $remoteLogin virsh list --name | grep $VM)" != "" ]; do
                sleep 2;
-       done
+       done
 }
 
 BackupOnlineVMs() {
@@ -93,13 +98,17 @@ BackupOnlineVMs() {
 }
 
 BackupOfflineVMs() {
-       offlineVM=$(ssh $remoteLogin virsh list --all | grep 'shut off' | awk '{print $2}')
+       offlineVM=$(ssh $remoteLogin virsh list --all \
+               | grep 'shut off' \
+               | awk '{print $2}')
 
        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}')
+               Disks=$(ssh $remoteLogin virsh domblklist $VM --details \
+                       | grep disk \
+                       | awk '{print $4}')
                BackupVMDiscs
                printfStripLine
        done
@@ -113,16 +122,19 @@ BackupVMs() {
 ################################################################################
 
 BackupDirectoryPath() {
+       local readonly logFile="$backRemotePCPath/backup-$(echo $pfad \
+               | sed 's/\//-/g').log"
+
        printfStripLine
        printf "Rechner %s; Pfad %s wird gesichert\n\n" "$remoterechner" "$pfad"
 
        rsync --archive --verbose --sparse --acls \
                --hard-links --relative --human-readable \
-               --log-file=$backupRemoteRechnerPath/backup-$(echo $pfad | sed 's/\//-/g').log \
+               --log-file=$logFile \
                --filter="- *.qcow2" --filter="- *.raw" \
                $hardlinkopt \
                $remoteLogin:$pfad \
-               $backupRemoteRechnerPath
+               $backRemotePCPath
        printfStripLine
 }
 
@@ -143,7 +155,7 @@ BackupRemotePC() {
                CreateBackupFolderRemotePC
                GetHardLinkOpts
 
-               backupRemoteRechnerPath="$sicherungspfad/$sicherungsordner/$remoterechner"
+               backRemotePCPath="$backpath/$backDir/$remoterechner"
                remoteLogin="$remoteuser@$remoterechner"
                
                BackupPathes
@@ -151,7 +163,10 @@ BackupRemotePC() {
 }
 
 CleanUpBackups() {
-       backupanzahl=$(ls --directory $sicherungspfad/*/ | grep "_$sicherungsname" | sort | wc --lines)
+       backupanzahl=$(ls --directory $backpath/*/ \
+               | grep "_$backname" \
+               | sort \
+               | wc --lines)
        loeschanzahl=$(($backupanzahl - $wunschanzahl))
 
        if [ $backupanzahl -gt $wunschanzahl ]
@@ -161,8 +176,8 @@ CleanUpBackups() {
                printf "Es sind %i Sicherungen vorhanden.\n" $backupanzahl
                printf "Es werden %i Sicherungen gelöscht.\n\n" $loeschanzahl
 
-               ls -d $sicherungspfad/*/ \
-                       | grep "_$sicherungsname" --max-count=$loeschanzahl \
+               ls -d $backpath/*/ \
+                       | grep "_$backname" --max-count=$loeschanzahl \
                        | xargs rm --recursive
 
                printfStripLine
index 3e9e9dea62aa3c7e6293e2fb14bd4da26e29583d..39af6e8866a28e90a5c8f8d2dfa0d88608227bfd 100755 (executable)
@@ -4,12 +4,12 @@
 
 # Informationen fuer den Sicherungsserver
 SetDefaultVariables() {
-       sicherungspfad="/images/backup"
-       sicherungsordner="einfach-sicherung"
+       backpath="/images/backup"
+       backDir="einfach-sicherung"
 }
 
 CreateBackupFolderRemotePC() {
-       mkdir --parents $sicherungspfad/$sicherungsordner/$remoterechner
+       mkdir --parents $backpath/$backDir/$remoterechner
 }
 
 printfStripLine() {
@@ -20,15 +20,19 @@ printfStripLine() {
 }
 
 BackupPathes() {
+       local readonly logFile="$backRemotePCPath/backup-$(echo $pfad \
+               | sed 's/\//-/g').log"
+
        for pfad in $(cat pfad-$remoterechner.txt); do
                printfStripLine
-               printf "\nRechner %s; Pfad %s wird gesichert\n\n" "$remoterechner" "$pfad"
+               printf "\nRechner %s; Pfad %s" "$remoterechner" "$pfad"
+               printf " wird gesichert\n\n"
 
-               rsync --archive --verbose --sparse --acls --hard-links --relative \
-                       --human-readable --delete \
-                       --log-file=$backupRemoteRechnerPath/backup-$(echo $pfad | sed 's/\//-/g').log \
+               rsync --archive --verbose --sparse --acls --hard-links \
+                       --relative --human-readable --delete \
+                       --log-file=$logFile \
                        $remoteLogin:$pfad \
-                       $backupRemoteRechnerPath
+                       $backRemotePCPath
                printfStripLine
        done
 }
@@ -39,7 +43,7 @@ BackupRemotePC() {
        for remoterechner in $(cat rechner.txt); do
                CreateBackupFolderRemotePC
 
-               backupRemoteRechnerPath="$sicherungspfad/$sicherungsordner/$remoterechner"
+               backRemotePCPath="$backpath/$backDir/$remoterechner"
                remoteLogin="$remoteuser@$remoterechner"
 
                BackupPathes
diff --git a/restore b/restore
index 21852a630290109bfdad3628a2a9d8f40dbc4311..a9d768c0ef5bd90532ce2486b0a58e9758145e49 100755 (executable)
--- a/restore
+++ b/restore
@@ -1,8 +1,8 @@
 #!/bin/bash
 
 SetDefaultVariables() {
-       sicherungspfad="/images/backup"
-       sicherungsname="sicherung"
+       backpath="/images/backup"
+       backname="sicherung"
 }
 
 ReadArguments() {
@@ -35,8 +35,8 @@ printfStripLine() {
 
 RestoreData() {
        remoteLogin="root@$rechner"
-       sicherungsordner="$datum"_"$sicherungsname"
-       fullPathSicherungsOrnder="$sicherungspfad/$sicherungsordner"
+       backDir="$datum"_"$backname"
+       fullPathSicherungsOrnder="$backpath/$backDir"
 
        printfStripLine
        printf "Daten werden wiederhergestellt\n\n"
@@ -45,8 +45,9 @@ RestoreData() {
        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 \
+       rsync --archive --verbose --sparse --acls --hard-links \
+               --human-readable \
+               --log-file $backpath/restore-$(date +%Y-%m-%d).log \
                $fullPathSicherungsordner/$rechner/$pfad \
                $remoteLogin:$pfad
 }
index b8d0bac311886a5118fcf122bc78f7e7e455d968..3bdc74e230f190a24fbb63b006d22d9f8bfcd5c4 100755 (executable)
@@ -1,8 +1,8 @@
 #!/bin/bash
 
 SetDefaultVariables() {
-       sicherungspfad="/images/backup"
-       sicherungsordner="einfach-sicherung"
+       backpath="/images/backup"
+       backDir="einfach-sicherung"
 }
 
 ReadArguments() {
@@ -32,7 +32,7 @@ printfStripLine() {
 
 RestoreData() {
        remoteLogin="root@$rechner"
-       fullPathSicherungsOrnder="$sicherungspfad/$sicherungsordner"
+       fullPathSicherungsOrnder="$backpath/$backDir"
 
        printfStripLine
        printf "Daten werden wiederhergestellt\n\n"
@@ -40,8 +40,9 @@ RestoreData() {
        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 \
+       rsync --archive --verbose --sparse --acls --hard-links \
+               --human-readable \
+               --log-file $backpath/restore-einfach-$(date +%Y-%m-%d).log \
                $fullPathSicherungsOrdner/$rechner/$pfad \
                $remoteLogin:$pfad
 }