-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigration.ps1
More file actions
98 lines (85 loc) · 1.96 KB
/
Copy pathmigration.ps1
File metadata and controls
98 lines (85 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env pwsh
#ever changed out an external drive? this way you can migrate everything, it will overwrite other files in the destination
param (
[string]$Source,
[string]$Destination,
[string]$LogFile = "~/Desktop/Purge.log",
[int]$ShutdownDelay = 30
)
# --- Interaktive Eingabe, falls vergessen ---
if (-not $Source) {
$Source = Read-Host "Pfad zum Quellordner: "
}
if (-not $Destination) {
$Destination = Read-Host "Pfad zum Zielordner: "
}
# --- Überprüfe ob Path existiert ---
foreach ($path in @($Source, $Destination)) {
if (-not (Test-Path -LiteralPath $path)) {
Write-Error "Pfad existiert nicht: $path"
exit 1
}
}
Write-Host "Starte Migration"
Write-Host "Quelle: $Source"
Write-Host "Ziel: $Destination"
Write-Host "Log: $LogFile"
if ($IsWindows) {
# --- Robocopy ---
$robocopyArgs = @(
$Source
$Destination
"/NP"
"/E"
"/ZB"
"/COPYALL"
"/R:2"
"/W:5"
"/TEE"
"/MIR"
"/LOG+:$LogFile"
)
& robocopy @robocopyArgs
$rc = $LASTEXITCODE
# Robocopy Exitcodes < 8 gelten als Erfolg
if ($rc -ge 8) {
Write-Error "Robocopy fehlgeschlagen (Exitcode $rc). Kein Shutdown."
exit 1
}
else {
Write-Host "Migration abgeschlossen (Exitcode $rc)."
# --- Shutdown ---
Write-Host "System fährt in $ShutdownDelay Sekunden herunter."
shutdown /s /f /t $ShutdownDelay
}
}
else {
# --- Validierung für rsync ---
if (-not (Get-Command rsync -ErrorAction SilentlyContinue)) {
Write-Error "rsync nicht gefunden. Abbruch."
exit 1
}
# --- rsync ---
$rsyncArgs = @(
"-a"
"--delete"
"--human-readable"
"--progress"
"--partial"
"--log-file=$LogFile"
"$Source/"
"$Destination/"
)
& rsync @rsyncArgs
$exitCode = $LASTEXITCODE
if ($exitCode -ne 0) {
Write-Error "rsync fehlgeschlagen (Exitcode $exitCode). Kein Shutdown."
exit 1
}
else {
Write-Host "Migration erfolgreich abgeschlossen."
# --- Shutdown ---
Write-Host "System fährt in $ShutdownDelay Sekunden herunter."
sudo shutdown -h +0
}
}