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 \
# 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 \
| 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
}
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
}
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/*/ \
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