Scripte vereinheitlicht

This commit is contained in:
Michael Grote 2021-03-18 09:08:22 +01:00
parent 8e0880d5a6
commit 244276a2e0
3 changed files with 95 additions and 94 deletions

View File

@ -1,14 +1,23 @@
#funktion get-scriptdirectory definieren um den scriptpfad ermitteln
# 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
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
#funktion an variable zuweisen
$scriptpfad = Get-ScriptDirectory
#hostname
# 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
# Hhostname
$hostname_ist = $env:computername
$hostname_soll = "irantu"
#ziele/quellen
# Ziele/Quellen
$quelle1 ="\\fileserver2.grote.lan\mg\"
$ziel1="$scriptpfad\backup\mg"
$quelle2 ="\\fileserver2.grote.lan\Musik\"
@ -40,26 +49,12 @@ if ($hostname_ist -eq $hostname_soll)
Exit 1
}
robocopy $quelle1 $ziel1 /MIR /R:3 /W:10 /XD "\\fileserver2.grote.lan\mg\Programme\Spiele - nicht gesichert"
robocopy $quelle2 $ziel2 /MIR /R:3 /W:10
robocopy $quelle3 $ziel3 /MIR /R:3 /W:10
robocopy $quelle4 $ziel4 /MIR /R:3 /W:10
robocopy $quelle5 $ziel5 /MIR /R:3 /W:10
robocopy $quelle6 $ziel6 /MIR /R:3 /W:10
robocopy $quelle7 $ziel7 /MIR /R:3 /W:10
robocopy $quelle8 $ziel8 /MIR /R:3 /W:10
robocopy $quelle9 $ziel9 /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
}
robocopy $quelle1 $ziel1 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle1.log" /XD "\\fileserver2.grote.lan\mg\Programme\Spiele - nicht gesichert"
robocopy $quelle2 $ziel2 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle2.log"
robocopy $quelle3 $ziel3 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle3.log"
robocopy $quelle4 $ziel4 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle4.log"
robocopy $quelle5 $ziel5 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle5.log"
robocopy $quelle6 $ziel6 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle6.log"
robocopy $quelle7 $ziel7 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle7.log"
robocopy $quelle8 $ziel8 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle8.log"
robocopy $quelle9 $ziel9 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle9.log"

View File

@ -1,29 +1,23 @@
#############################################################################
# Michael Grote - 21.11.2019 #
# Kopierscript für Daueraufgaben #
# Script "mirrored" bis zu 6 komplette Ordner #
# Es wird jeweils ein Log pro Kopiervorgang angelegt #
# nicht benötigt Ordner MÜSSEN auskommentiert werden #
# - sowohl bei den Variablen als auch de Kopiervorgängen selber #
# Programme können auch auskommentiert werden wenn nciht benötigt #
#############################################################################
#Variablen
#Variablen setzen
#variablendeklaration pfade
#scriptpfad ermitteln
#funktion get-scriptdirectory definieren
# 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
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
#funktion an variable zuweisen
$scriptpfad = Get-ScriptDirectory
#hostname
# 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
# Hhostname
$hostname_ist = $env:computername
$hostname_soll = "irantu"
#ziele/quellen
# Ziele/Quellen
$quelle1 = "C:\VM"
$quelle2 = "C:\Portable_Programme"
$quelle3 = "C:\Users\mg\Desktop"
@ -43,45 +37,6 @@ if ($hostname_ist -eq $hostname_soll)
}
# Prüfungen Ordner existend und kopieren
if(Test-Path $ziel1)
{
robocopy $quelle1 $ziel1 /MIR /ETA /R:3 /W:10
}
else
{
New-Item "$ziel1" -ItemType Directory
robocopy $quelle1 $ziel1 /MIR /ETA /R:3 /W:10
}
if(Test-Path $ziel2)
{
robocopy $quelle2 $ziel2 /MIR /ETA /R:3 /W:10
}
else
{
New-Item "$ziel2" -ItemType Directory
robocopy $quelle2 $ziel2 /MIR /ETA /R:3 /W:10
}
if(Test-Path $ziel3)
{
robocopy $quelle3 $ziel3 /MIR /ETA /R:3 /W:10
}
else
{
New-Item "$ziel3" -ItemType Directory
robocopy $quelle3 $ziel3 /MIR /ETA /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
}
robocopy $quelle1 $ziel1 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle1.log"
robocopy $quelle2 $ziel2 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle2.log"
robocopy $quelle3 $ziel3 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle3.log"

51
nas_papa-hdds.ps1 Normal file
View File

@ -0,0 +1,51 @@
# 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
# Hhostname
$hostname_ist = $env:computername
$hostname_soll = "andreasgrote"
# Ziele/Quellen
$quelle1 ="\\nas.local\backup\"
$ziel1="$scriptpfad\backup\backup"
$quelle2 ="\\nas.local\bilder\"
$ziel2="$scriptpfad\backup\bilder"
$quelle3 ="\\nas.local\dokumente\"
$ziel3="$scriptpfad\backup\dokumente"
$quelle4 ="\\nas.local\musik\"
$ziel4="$scriptpfad\backup\musik"
$quelle5 ="\\nas.local\videos"
$ziel5="$scriptpfad\backup\videos"
$quelle6 ="\\nas.local\rest"
$ziel6="$scriptpfad\backup\rest"
# 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 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle1.log"
robocopy $quelle2 $ziel2 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle2.log"
robocopy $quelle3 $ziel3 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle3.log"
robocopy $quelle4 $ziel4 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle4.log"
robocopy $quelle5 $ziel5 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle5.log"
robocopy $quelle6 $ziel6 /MIR /R:3 /W:10 /DST /TEE /UNILOG+:"$scriptpfad\$timestamp_$quelle6.log"