<# Backup del entorno PowerShell + SSH. Incluye: perfil, historial PSReadLine, ssh_config (ruta actual) y opcional llaves. #> param( [string]$RepoConfig = "C:\Users\ofgar\Workspace\revelation\ssh_config", [string]$BackupRoot = (Join-Path $env:USERPROFILE "Documents\pwsh_ssh_backup"), [switch]$IncludeKeys ) $ErrorActionPreference = "Stop" $ts = Get-Date -Format "yyyyMMdd_HHmmss" $dst = Join-Path $BackupRoot $ts New-Item -ItemType Directory -Force -Path $dst | Out-Null function SafeCopy([string]$src, [string]$name) { if (Test-Path -LiteralPath $src) { Copy-Item -LiteralPath $src -Destination (Join-Path $dst $name) -Force Write-Host "OK: $name" } else { Write-Warning "No existe: $src" } } # 1) Perfil PowerShell SafeCopy $PROFILE "Microsoft.PowerShell_profile.ps1" # 2) Historial PSReadLine $hist = (Get-PSReadLineOption).HistorySavePath SafeCopy $hist "ConsoleHost_history.txt" # 3) ssh_config (ruta actual) SafeCopy $RepoConfig "ssh_config" # 4) Inventario de módulos Get-InstalledModule | Select Name, Version | Sort Name | Out-File (Join-Path $dst "pwsh_modules.txt") -Encoding UTF8 Write-Host "OK: pwsh_modules.txt" # 5) Opcional: llaves y archivos SSH if ($IncludeKeys) { $sshDir = Join-Path $env:USERPROFILE ".ssh" SafeCopy (Join-Path $sshDir "id_rsa") "id_rsa" SafeCopy (Join-Path $sshDir "id_rsa.pub") "id_rsa.pub" SafeCopy (Join-Path $sshDir "known_hosts") "known_hosts" SafeCopy (Join-Path $sshDir "config") "config_current" } # 6) Info general $info = Join-Path $dst "env_info.txt" "PowerShell: $($PSVersionTable.PSVersion)" | Out-File $info -Encoding UTF8 "PROFILE: $PROFILE" | Add-Content $info "PSReadLineHistory: $hist" | Add-Content $info "RepoConfig: $RepoConfig" | Add-Content $info Write-Host "" Write-Host "Backup creado en: $dst"