Skip to content

Instantly share code, notes, and snippets.

@themaximax
Created November 6, 2025 06:31
Show Gist options
  • Select an option

  • Save themaximax/0e417a035404c15fbd8bb4a84ad764d6 to your computer and use it in GitHub Desktop.

Select an option

Save themaximax/0e417a035404c15fbd8bb4a84ad764d6 to your computer and use it in GitHub Desktop.
Скрипт резервного копирования PSW
$backupRoot = "C:\Backup"
$timestamp = Get-Date -Format 'yyyyMMdd_HHmmss'
$excludeDirs = @("logs", "vcredist")
# === Проверка и создание корневой папки бэкапа ===
if (-not (Test-Path $backupRoot)) {
try {
New-Item -ItemType Directory -Path $backupRoot -Force -ErrorAction Stop | Out-Null
} catch {
Write-Error "Не удалось создать папку для бэкапа: $backupRoot"
exit 1
}
}
# === Таблица соответствия программ и путей ===
$backupMap = @{
"PSWServer" = "C:\PSWServer"
"PSWSystemOffice" = "C:\PSWOffice"
"PSWAdministrator" = "C:\PSWOffice"
"PSWSystem" = "C:\PSWSystem"
}
# === 1. Бэкап веток реестра ===
$regPath = "HKCU:\Software\SLA"
if (Test-Path $regPath) {
foreach ($regKey in $backupMap.Keys) {
$fullRegPath = Join-Path $regPath $regKey
if (Test-Path $fullRegPath) {
$regFile = "${regKey}_${timestamp}.reg"
reg export "HKCU\Software\SLA\$regKey" (Join-Path $backupRoot $regFile) /y | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Host "Реестр: $regKey" -ForegroundColor Cyan
} else {
Write-Warning "Ошибка при экспорте ветки реестра: $regKey"
}
}
}
}
# === 2. Бэкап программных папок ===
$uniquePaths = $backupMap.Values | Sort-Object -Unique
foreach ($path in $uniquePaths) {
if (Test-Path $path) {
$folderName = [System.IO.Path]::GetFileName($path)
$dest = Join-Path $backupRoot "${folderName}_${timestamp}"
robocopy $path $dest /E /XD $excludeDirs /R:1 /W:1 /NP | Out-Null
if ($LASTEXITCODE -lt 8) {
Write-Host "Папка: $path → $dest" -ForegroundColor Cyan
} else {
Write-Warning "Ошибки при копировании: $path"
}
}
}
Write-Host "Готово! Бэкапы сохранены в: $backupRoot" -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment