param( [string]$BackupRoot = "H:\Windows-Neuaufsetzen-Backup", [string]$UserProfilePath = $env:USERPROFILE, [switch]$IncludeOllama ) Set-StrictMode -Version Latest $ErrorActionPreference = "Stop" function Invoke-RobocopyBackup { param( [string]$Source, [string]$Destination, [string]$LogName ) if (-not (Test-Path $Source)) { Write-Host "SKIP missing source: $Source" return } New-Item -ItemType Directory -Force -Path $Destination | Out-Null $LogDir = Join-Path $BackupRoot "12_Exportierte_Listen" New-Item -ItemType Directory -Force -Path $LogDir | Out-Null $LogPath = Join-Path $LogDir $LogName Write-Host "COPY $Source" Write-Host " -> $Destination" robocopy $Source $Destination /E /COPY:DAT /DCOPY:DAT /R:2 /W:2 /XJ /TEE /LOG:$LogPath $ExitCode = $LASTEXITCODE if ($ExitCode -gt 7) { throw "Robocopy failed with exit code $ExitCode for source: $Source" } } if (-not (Test-Path $BackupRoot)) { throw "BackupRoot does not exist: $BackupRoot" } if (-not (Test-Path $UserProfilePath)) { throw "UserProfilePath does not exist: $UserProfilePath" } $CurrentUserJobs = @( @{ Source = Join-Path $UserProfilePath "Desktop"; Destination = Join-Path $BackupRoot "01_Desktop"; Log = "backup_current_desktop.log" }, @{ Source = Join-Path $UserProfilePath "Documents"; Destination = Join-Path $BackupRoot "02_Dokumente"; Log = "backup_current_documents.log" }, @{ Source = Join-Path $UserProfilePath "Pictures"; Destination = Join-Path $BackupRoot "03_Bilder"; Log = "backup_current_pictures.log" }, @{ Source = Join-Path $UserProfilePath "Videos"; Destination = Join-Path $BackupRoot "04_Videos"; Log = "backup_current_videos.log" }, @{ Source = Join-Path $UserProfilePath "Downloads"; Destination = Join-Path $BackupRoot "05_Downloads_wichtig\_current_downloads_all"; Log = "backup_current_downloads.log" }, @{ Source = Join-Path $UserProfilePath "Music"; Destination = Join-Path $BackupRoot "15_Musik"; Log = "backup_current_music.log" }, @{ Source = Join-Path $UserProfilePath ".ssh"; Destination = Join-Path $BackupRoot "09_Programme_Settings_Lizenzen\ssh"; Log = "backup_current_ssh.log" } ) foreach ($Job in $CurrentUserJobs) { Invoke-RobocopyBackup -Source $Job.Source -Destination $Job.Destination -LogName $Job.Log } $GitConfig = Join-Path $UserProfilePath ".gitconfig" if (Test-Path $GitConfig) { $GitDest = Join-Path $BackupRoot "09_Programme_Settings_Lizenzen\git" New-Item -ItemType Directory -Force -Path $GitDest | Out-Null Copy-Item -LiteralPath $GitConfig -Destination (Join-Path $GitDest ".gitconfig") -Force } $OldUserRoot = "D:\Users\Baerchen" $OldUserJobs = @( @{ Source = Join-Path $OldUserRoot "Desktop"; Destination = Join-Path $BackupRoot "99_Unsortiert_von_D_F_G\D_Users_Baerchen\Desktop"; Log = "backup_old_baerchen_desktop.log" }, @{ Source = Join-Path $OldUserRoot "Documents"; Destination = Join-Path $BackupRoot "99_Unsortiert_von_D_F_G\D_Users_Baerchen\Documents"; Log = "backup_old_baerchen_documents.log" }, @{ Source = Join-Path $OldUserRoot "Pictures"; Destination = Join-Path $BackupRoot "99_Unsortiert_von_D_F_G\D_Users_Baerchen\Pictures"; Log = "backup_old_baerchen_pictures.log" }, @{ Source = Join-Path $OldUserRoot "Videos"; Destination = Join-Path $BackupRoot "99_Unsortiert_von_D_F_G\D_Users_Baerchen\Videos"; Log = "backup_old_baerchen_videos.log" }, @{ Source = Join-Path $OldUserRoot "Downloads"; Destination = Join-Path $BackupRoot "99_Unsortiert_von_D_F_G\D_Users_Baerchen\Downloads"; Log = "backup_old_baerchen_downloads.log" }, @{ Source = Join-Path $OldUserRoot "Music"; Destination = Join-Path $BackupRoot "99_Unsortiert_von_D_F_G\D_Users_Baerchen\Music"; Log = "backup_old_baerchen_music.log" } ) foreach ($Job in $OldUserJobs) { Invoke-RobocopyBackup -Source $Job.Source -Destination $Job.Destination -LogName $Job.Log } $ExtraJobs = @( @{ Source = "F:\BMW Leasing"; Destination = Join-Path $BackupRoot "07_Banking_Finanzen\BMW Leasing"; Log = "backup_f_bmw_leasing.log" }, @{ Source = "F:\Marina Handy 2025"; Destination = Join-Path $BackupRoot "03_Bilder\Marina Handy 2025"; Log = "backup_f_marina_handy_2025.log" }, @{ Source = "F:\Marina Handy Backup"; Destination = Join-Path $BackupRoot "03_Bilder\Marina Handy Backup"; Log = "backup_f_marina_handy_backup.log" }, @{ Source = "G:\Gitea_Clone"; Destination = Join-Path $BackupRoot "06_Projekte\Gitea_Clone"; Log = "backup_g_gitea_clone.log" }, @{ Source = "G:\open-webui"; Destination = Join-Path $BackupRoot "09_Programme_Settings_Lizenzen\open-webui"; Log = "backup_g_open_webui.log" }, @{ Source = "G:\Treiber"; Destination = Join-Path $BackupRoot "13_Treiber_Windows\G_Treiber"; Log = "backup_g_treiber.log" } ) if ($IncludeOllama) { $ExtraJobs += @{ Source = "G:\Ollama"; Destination = Join-Path $BackupRoot "09_Programme_Settings_Lizenzen\Ollama"; Log = "backup_g_ollama.log" } } foreach ($Job in $ExtraJobs) { Invoke-RobocopyBackup -Source $Job.Source -Destination $Job.Destination -LogName $Job.Log } Write-Host "" Write-Host "Known-data backup finished." Write-Host "Backup root: $BackupRoot" Write-Host "Logs: $BackupRoot\12_Exportierte_Listen" if (-not $IncludeOllama) { Write-Host "Note: G:\Ollama was not copied. Re-run with -IncludeOllama if you want to keep local models too." }