powershell_kopierscripte/fileserver-hdds-alles.ps1

92 lines
3.4 KiB
PowerShell

# Funktion: speichert den aktuellen Pfad(vgl. pwd) in Get-ScriptDirectory
function Get-ScriptDirectory {
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
# Funktion: setze Timestamp, mit Rückgabewert
function get-timestamp{
$timestamp = (get-date -Format yyyy_MM_dd__HH_mm_ss)
return $timestamp
}
# restliche Variablen
$timestamp = get-timestamp # Ruft Funktion get-timestamp auf
$scriptpfad = Get-ScriptDirectory # setzt $scriptpfad auf den Wert von Get-ScriptDirectory
# Hostname
$hostname_ist = $env:computername
$hostname_soll = "irantu"
# Ziele/Quellen
$quelle1 ="\\fileserver3.grote.lan\buecher"
$quelle2 ="\\fileserver3.grote.lan\Musik"
$quelle3 ="\\fileserver3.grote.lan\proxmox"
$quelle4 ="\\fileserver3.grote.lan\backup"
$quelle5 ="\\fileserver3.grote.lan\archiv"
$quelle6 ="\\fileserver3.grote.lan\programme"
$quelle7 ="\\fileserver3.grote.lan\bilder"
$quelle9 ="\\fileserver3.grote.lan\vm"
$quelle10 ="\\fileserver3.grote.lan\hm"
$quelle11 ="\\fileserver3.grote.lan\tmp"
$quelle12 ="C:\portable_programme"
$quelle13 ="C:\Users\mg\desktop"
$quelle1_name= "buecher"
$quelle2_name= "musik"
$quelle2_name= "proxmox"
$quelle4_name= "backup"
$quelle5_name= "archiv"
$quelle6_name= "programme"
$quelle3_name= "proxmox"
$quelle7_name= "bilder"
$quelle9_name= "vm"
$quelle10_name= "hm"
$quelle11_name= "tmp"
$quelle12_name= "portable_programme"
$quelle13_name= "Desktop"
$ziel1="$scriptpfad\backup\buecher"
$ziel2="$scriptpfad\backup\Musik"
$ziel4="$scriptpfad\backup\backup"
$ziel5="$scriptpfad\backup\archiv"
$ziel6="$scriptpfad\backup\programme"
$ziel7="$scriptpfad\backup\bilder"
$ziel9="$scriptpfad\backup\vm"
$ziel10="$scriptpfad\backup\hm"
$ziel11="$scriptpfad\backup\tmp"
$ziel3="$scriptpfad\backup\proxmox"
$ziel12="$scriptpfad\backup\portable_programme"
$ziel13="$scriptpfad\backup\desktop"
# 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
}
# logs Ordner erstellen
If(!(test-path $scriptpfad\logs))
{
New-Item -ItemType Directory -Force -Path $scriptpfad\logs
}
robocopy $quelle1 $ziel1 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle1_name.log"
robocopy $quelle2 $ziel2 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle2_name.log"
robocopy $quelle3 $ziel3 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle3_name.log"
robocopy $quelle4 $ziel4 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle4_name.log"
robocopy $quelle5 $ziel5 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle5_name.log"
robocopy $quelle6 $ziel6 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle6_name.log"
robocopy $quelle7 $ziel7 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle7_name.log"
robocopy $quelle8 $ziel8 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle8_name.log"
robocopy $quelle9 $ziel9 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle9_name.log" /XD "\\fileserver3.grote.lan\vm\Mint_lol"
robocopy $quelle10 $ziel10 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle10_name.log"
robocopy $quelle11 $ziel811/MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\logs\$timestamp-$quelle11_name.log"