powershell_kopierscripte/fileserver2_sichern_dryrun.ps1

64 lines
2.0 KiB
PowerShell

#funktion get-scriptdirectory definieren um den scriptpfad ermitteln
function Get-ScriptDirectory {
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
#funktion an variable zuweisen
$scriptpfad = Get-ScriptDirectory
#hostname
$hostname_ist = $env:comput
ername
$hostname_soll = "irantu"
#ziele/quellen
$quelle1 ="\\fileserver2.grote.lan\mg\"
$ziel1="$scriptpfad\backup\mg"
$quelle2 ="\\fileserver2.grote.lan\Musik\"
$ziel2="$scriptpfad\backup\Musik"
$quelle3 ="\\fileserver2.grote.lan\amd\"
$ziel3="$scriptpfad\backup\amd"
$quelle4 ="\\fileserver2.grote.lan\backup\"
$ziel4="$scriptpfad\backup\backup"
$quelle5 ="\\fileserver2.grote.lan\Videos\Filme - ueberragende"
$ziel5="$scriptpfad\backup\Videos\Filme - ueberragende"
$quelle6 ="\\fileserver2.grote.lan\Videos\Serien - überragende"
$ziel6="$scriptpfad\backup\Videos\Serien - ueberragende"
$quelle7 ="\\fileserver2.grote.lan\bilder"
$ziel7="$scriptpfad\backup\bilder"
$quelle8 ="\\fileserver2.grote.lan\videos\Youtube"
$ziel8="$scriptpfad\backup\Videos\youtube"
# Hostname prüfen
if ($hostname_ist -eq $hostname_soll)
{
Write-Host "Host = $hostname_ist"
}
else
{
Write-Host "Falscher Host(SOLL: '$hostname_soll' IST:$hostname_ist)"
start-sleep 5
Exit 1
}
robocopy $quelle1 $ziel1 /L /MIR /R:3 /W:10 /XD "\\fileserver2.grote.lan\mg\Programme\Spiele - nicht gesichert"
robocopy $quelle2 $ziel2 /L /MIR /R:3 /W:10
robocopy $quelle3 $ziel3 /L /MIR /R:3 /W:10
robocopy $quelle4 $ziel4 /L /MIR /R:3 /W:10
robocopy $quelle5 $ziel5 /L /MIR /R:3 /W:10
robocopy $quelle6 $ziel6 /L /MIR /R:3 /W:10
robocopy $quelle7 $ziel7 /L /MIR /R:3 /W:10
robocopy $quelle8 $ziel8 /L /MIR /R:3 /W:10
#Rückgabecoce robocopy auswerten
#robocopy exit codes
#https://support.microsoft.com/en-us/help/954404/return-codes-that-are-used-by-the-robocopy-utility-in-windows-server-2
if ($lastexitcode -eq 1)
{
write-host "Keine Fehler!"
}
else
{
#`n ist newline
write-host `n`n`n`n`n`n`n`n`n`n`n`n"Es sind Fehler aufgetreten!"`n`n`n`n`n`n`n`n`n`n`n`n
start-sleep 43200
}