From: Bastian Dehn Date: Sat, 25 Nov 2017 16:42:26 +0000 (+0100) Subject: fix: 80 character line length X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=5192745935ece1a5f69f2d6c8189c7b506895b5d;p=simple-backup.git fix: 80 character line length --- diff --git a/backup b/backup index 829cc6c..50e0679 100755 --- 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 diff --git a/backup-einfach b/backup-einfach index 3e9e9de..39af6e8 100755 --- a/backup-einfach +++ b/backup-einfach @@ -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 21852a6..a9d768c 100755 --- 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 } diff --git a/restore-einfach b/restore-einfach index b8d0bac..3bdc74e 100755 --- a/restore-einfach +++ b/restore-einfach @@ -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 }