]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
change: display delete old backup
authorBastian Dehn <hhaalo@arcor.de>
Tue, 17 Jul 2018 18:35:23 +0000 (20:35 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 17 Jul 2018 18:35:23 +0000 (20:35 +0200)
Loesche alte Backups und zeige diese an. Code
optimierung durch neue Funktion LoescheVerzeich-
nisse und BackupTypOfVMDisc

backup

diff --git a/backup b/backup
index 24cae341d37a46ad4844b6eb8f173d4486b3b626..60b322a8f256e0beadc767018ae6d7b9aaee9185 100755 (executable)
--- a/backup
+++ b/backup
@@ -28,10 +28,13 @@ ReadArguments()
 CreateBackupFolder()
 {
        local dayAnzahl=1
-       backDir="$(date +%Y-%m-%d)"_"$(printf "%02d" $dayAnzahl)"_"$backname"
+       local fullnum=$(printf "%02d" $dayAnzahl)
+
+       backDir="$(date +%Y-%m-%d)"_"$fullnum"_"$backname"
        while [ -d $backpath/$backDir ]; do
                ((dayAnzahl++))
-               backDir="$(date +%Y-%m-%d)"_"$(printf "%02d" $dayAnzahl)"_"$backname"
+               fullnum=$(printf "%02d" $dayAnzahl)
+               backDir="$(date +%Y-%m-%d)"_"$fullnum"_"$backname"
        done
 
        tmpordner=$(find $backpath -maxdepth 1 -type d \
@@ -65,6 +68,26 @@ printfStripLine()
 # Backup VMs
 ################################################################################
 
+BackupTypOfVMDisc()
+{
+       if [ "$DiskType" == "file" ]; then
+               rsync --archive --verbose --sparse --acls --hard-links \
+                       --relative --progress --human-readable \
+                       --log-file=$logFile $hardlinkopt $remoteLogin:$Disk \
+                       $backRemotePCPath
+       elif [ "$DiskType" == "block" ]; then
+               local readonly DiskName=$(echo $Disk | sed 's/^\///' \
+                       | sed 's/\//-/g')
+               local readonly DiskSize=$(ssh $remoteLogin fdisk --list $Disk \
+                       | head --lines=1 | awk \
+                       --field-separator="," '{print $2}' \
+                       | sed 's/[ \| Bbytes]//g')
+
+               ssh $remoteLogin dd bs=1M if=$Disk | pv --size $DiskSize \
+                       | gzip --stdout | dd of=$backRemotePCPath/$DiskName.gz
+       fi
+}
+
 BackupVMDiscs()
 {
        local readonly Disks=$(ssh $remoteLogin virsh domblklist $VM --details \
@@ -80,25 +103,7 @@ BackupVMDiscs()
                        | grep Type | awk '{print $2}')
                logFile="$backRemotePCPath/backup-$(echo $Disk \
                        | sed 's/\//-/g').log"
-
-               if [ "$DiskType" == "file" ]; then
-                       rsync --archive --verbose --sparse --acls --hard-links \
-                               --relative --progress --human-readable \
-                               --log-file=$logFile \
-                               $hardlinkopt \
-                               $remoteLogin:$Disk $backRemotePCPath
-               elif [ "$DiskType" == "block" ]; then
-                       local readonly DiskName=$(echo $Disk \
-                               | sed 's/^\///' | sed 's/\//-/g')
-                       local readonly DiskSize=$(ssh $remoteLogin fdisk --list \
-                               $Disk | head --lines=1 | awk \
-                               --field-separator="," '{print $2}' \
-                               | sed 's/[ \| Bbytes]//g')
-
-                       ssh $remoteLogin dd bs=1M if=$Disk \
-                               | pv --size $DiskSize | gzip --stdout \
-                               | dd of=$backRemotePCPath/$DiskName.gz
-               fi
+               BackupTypOfVMDisc
        done
 }
 
@@ -155,12 +160,9 @@ BackupDirectoryPath()
        printfStripLine
        printf "Rechner %s; Pfad %s wird gesichert\n\n" "$remoterechner" "$pfad"
 
-       rsync --archive --verbose --sparse --acls \
-               --hard-links --relative --human-readable \
-               --log-file=$logFile \
-               --filter="- *.qcow2" --filter="- *.raw" \
-               $hardlinkopt \
-               $remoteLogin:$pfad \
+       rsync --archive --verbose --sparse --acls --hard-links --relative \
+               --human-readable --log-file=$logFile --filter="- *.qcow2" \
+               --filter="- *.raw" $hardlinkopt $remoteLogin:$pfad \
                $backRemotePCPath
        printfStripLine
 }
@@ -208,6 +210,15 @@ BackupRemotePC()
        done
 }
 
+LoescheVerzeichnisse()
+{
+       for i in $(ls --directory $backpath/*/ | grep "_$backname" \
+               --max-count=$loeshanzahl); do
+               printf "Lösche %s\n" $i
+               rm --recursive $i
+       done
+}
+
 CleanUpBackups()
 {
        backupanzahl=$(ls --directory $backpath/*/ \
@@ -222,11 +233,8 @@ CleanUpBackups()
                printf "\n"
                printf "Es sind %i Sicherungen vorhanden.\n" $backupanzahl
                printf "Es werden %i Sicherungen gelöscht.\n\n" $loeschanzahl
-
-               ls --directory $backpath/*/ \
-                       | grep "_$backname" --max-count=$loeschanzahl \
-                       | xargs rm --recursive
-
+               LoescheVerzeichnisse
+               printf "\n"
                printfStripLine
        else
                printfStripLine