### vorhaerigen Backup
SetDefaultVariables() {
- sicherungspfad="/images/backup"
- sicherungsname="sicherung"
+ backpath="/images/backup"
+ backname="sicherung"
wunschanzahl=20
mode="incremental"
}
}
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
}
################################################################################
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() {
}
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
################################################################################
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
}
CreateBackupFolderRemotePC
GetHardLinkOpts
- backupRemoteRechnerPath="$sicherungspfad/$sicherungsordner/$remoterechner"
+ backRemotePCPath="$backpath/$backDir/$remoterechner"
remoteLogin="$remoteuser@$remoterechner"
BackupPathes
}
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 ]
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
# 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() {
}
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
}
for remoterechner in $(cat rechner.txt); do
CreateBackupFolderRemotePC
- backupRemoteRechnerPath="$sicherungspfad/$sicherungsordner/$remoterechner"
+ backRemotePCPath="$backpath/$backDir/$remoterechner"
remoteLogin="$remoteuser@$remoterechner"
BackupPathes
#!/bin/bash
SetDefaultVariables() {
- sicherungspfad="/images/backup"
- sicherungsname="sicherung"
+ backpath="/images/backup"
+ backname="sicherung"
}
ReadArguments() {
RestoreData() {
remoteLogin="root@$rechner"
- sicherungsordner="$datum"_"$sicherungsname"
- fullPathSicherungsOrnder="$sicherungspfad/$sicherungsordner"
+ backDir="$datum"_"$backname"
+ fullPathSicherungsOrnder="$backpath/$backDir"
printfStripLine
printf "Daten werden wiederhergestellt\n\n"
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
}
#!/bin/bash
SetDefaultVariables() {
- sicherungspfad="/images/backup"
- sicherungsordner="einfach-sicherung"
+ backpath="/images/backup"
+ backDir="einfach-sicherung"
}
ReadArguments() {
RestoreData() {
remoteLogin="root@$rechner"
- fullPathSicherungsOrnder="$sicherungspfad/$sicherungsordner"
+ fullPathSicherungsOrnder="$backpath/$backDir"
printfStripLine
printf "Daten werden wiederhergestellt\n\n"
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
}