Files
solution-erp/scripts/backup-sql.ps1
pqhuy1987 ff7f6559a7
Some checks failed
Deploy SOLUTION_ERP / build-deploy (push) Has been cancelled
[CLAUDE] Docs: S168 closeout — bookend @close 5 vong/9 vai + va 12 FLAG + MIND-5 + so-phieu-that 003->004
- Bookend @close: V1 H1 PWF-7 + H2 GATE-FAIL-5 -> ring1 52D/4T · V2 stale 8-FLAG + gap 7-FLAG (gap-owner-specifics CHAM JUMP=3) · V3 eval MIXED-25 + refine 2-action/14-BAC · V4 SKIP-co-khai (0/17 shard hop le, guard khop-ten-cap khong kich) · V5 floor phep DAT 4/TRUOT 0/vacuous 0
- 🔴 3 vai chet API session-limit => no PIN san: ring2-audit + ctx-audit (ruot partial tren dia) + harness-audit (MAT RETURN) => V3 phien nay KHONG co nac KIEM, khai thang
- Va FLAG cung phien: 7 site D:\Backups->C:\ (site-7 architecture.md:220 do ring1 bat) · skill ef-core +row Mig 70/71 · stray dir cwd-misland · FID-1 khai tac-gia LEAD · STATUS moc S156->S168 + Recently-Done S168 + no-GD3-dong · HANDOFF header + dong slot (63)(59) + them (64)(65)(66) · run.md ledger 6 row
- 🔴 STATUS+WAL "phieu KHKK that dau = 003" -> 004 (lead-gap F-2 bat, lead do prod sqlcmd xac nhan 001-002-003 deu la phieu test)
- MIND-5 chen (window-6 nang nhat L9) — mind-check 11D/0T · session-log S168 · memory entry dryrun-finds-promised-but-unlanded

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-01 20:37:47 +07:00

58 lines
1.7 KiB
PowerShell

# Backup SQL Server database SolutionErp.
# Lập lịch qua Task Scheduler: daily 2:00 AM.
#
# Usage:
# .\scripts\backup-sql.ps1 -Server "." -Database "SolutionErp" -BackupDir "C:\Backups\SolutionErp"
#
# Retention: giữ 30 ngày gần nhất (dọn file cũ hơn 30d).
param(
[string]$Server = ".",
[string]$Database = "SolutionErp",
# [S168 K8 B0] Default C:\ — VPS prod KHONG co o D (do that: mkdir D:\ fail
# "Cannot find drive"); D:\ cu la gia dinh chua tung chay tren may nay.
[string]$BackupDir = "C:\Backups\SolutionErp",
[int]$RetentionDays = 30
)
$ErrorActionPreference = 'Stop'
if (-not (Test-Path $BackupDir)) {
New-Item -ItemType Directory -Force -Path $BackupDir | Out-Null
}
$timestamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$backupFile = Join-Path $BackupDir "${Database}_${timestamp}.bak"
Write-Host "Backup $Database -> $backupFile"
$sql = @"
BACKUP DATABASE [$Database]
TO DISK = N'$backupFile'
WITH
INIT,
COMPRESSION,
CHECKSUM,
NAME = N'$Database-Full-$timestamp',
DESCRIPTION = N'Daily full backup';
"@
sqlcmd -S $Server -Q $sql -b
if ($LASTEXITCODE -ne 0) {
throw "Backup FAIL (exit code $LASTEXITCODE)"
}
$fileSize = [math]::Round((Get-Item $backupFile).Length / 1MB, 2)
Write-Host " Size: ${fileSize} MB"
# Retention: xoa file cu hon X ngay
Write-Host "Cleanup old backups (>$RetentionDays days)"
$cutoff = (Get-Date).AddDays(-$RetentionDays)
$oldFiles = Get-ChildItem -Path $BackupDir -Filter "*.bak" | Where-Object { $_.LastWriteTime -lt $cutoff }
foreach ($f in $oldFiles) {
Write-Host " Remove $($f.Name)"
Remove-Item $f.FullName -Force
}
Write-Host "`nBackup SUCCESS" -ForegroundColor Green