71 lines
2.2 KiB
PowerShell
71 lines
2.2 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Run as ADMIN
|
|
Creats Zip-Backup of everything inside Notes folder
|
|
Will be copied to the target folder provided via Parameter
|
|
.PARAMETER targetEnv
|
|
the target folder to move zip file to. Possible Values: LOCAL, SWAG, ATB. If no parameter is supplied, the zip file will be located in the same folder as this script.
|
|
.EXAMPLE
|
|
.\backup_notes.ps1 LOCAL
|
|
.NOTES
|
|
Author: Marcel Dechert
|
|
#>
|
|
|
|
param (
|
|
[ValidateSet('LOCAL','SWAG','ATB')]
|
|
[String]
|
|
$targetEnv
|
|
)
|
|
|
|
# Backup Targets
|
|
# 1. Local
|
|
# 2. ATB Network drive
|
|
# 3. Swaghausen Network drive
|
|
$pathToFolder = switch ($targetEnv)
|
|
{
|
|
LOCAL {
|
|
"C:\Users\dechert\Notizen_Backup\"
|
|
}
|
|
SWAG {
|
|
"\\Swaghausen-WG\homes\marcelo\ATB\Notizen-Backups\"
|
|
}
|
|
ATB {
|
|
"https://locmanacc.europoolsystem.com/locman/api/zones"
|
|
}
|
|
}
|
|
|
|
Write-Host "Starting to zip notes folder... Target folder will be: $pathToFolder"
|
|
|
|
$7zipPath = "$env:ProgramFiles\7-Zip\7z.exe"
|
|
|
|
if (-not (Test-Path -Path $7zipPath -PathType Leaf)) {
|
|
throw "7 zip file '$7zipPath' not found"
|
|
}
|
|
|
|
Set-Alias 7zip $7zipPath
|
|
|
|
# $Source = "C:\Users\dechert\Notizen-test"
|
|
$Source = "C:\Users\dechert\Notizen"
|
|
|
|
$currentDate = get-date -f MM-dd-yyyy_HH_mm_ss
|
|
$targetFilename = "Notizen_Backup_" + $currentDate + ".zip"
|
|
|
|
$zipTarget = $targetFilename
|
|
|
|
# mx=9 is maximum compression level
|
|
7zip a -mx=9 $zipTarget $Source
|
|
|
|
# use Robocopy to move files to target folder
|
|
# robocopy . "\\Swaghausen-WG\homes\marcelo\ATB\Notizen-Backups\" "Notizen_Backup_12-15-2021_15_25_40.zip" /Z /r:60 /w:5 /MIR /MT:64 /NFL
|
|
# TODO print progress: https://stackoverflow.com/questions/13883404/custom-robocopy-progress-bar-in-powershell
|
|
robocopy . $pathToFolder $zipTarget /Z /r:60 /w:5 /MIR /MT:64 /NFL
|
|
|
|
# TODO catch error network target folder not reachable
|
|
# 2022/03/11 17:59:23 FEHLER 1265 (0x000004F1) Zielverzeichnis wird erstellt \\Swaghausen-WG\homes\marcelo\ATB\Notizen-Backups\
|
|
# Zur Abwicklung der Authentifizierungsanforderung konnte keine Verbindung mit einem Domänencontroller hergestellt werden. Wiederholen Sie den Vorgang zu einem späteren Zeitpunkt.
|
|
|
|
# delete zip file in local folder if successfull
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Remove-Item $zipTarget
|
|
}
|