Files
solution-erp/scripts/backup-sql.ps1
pqhuy1987 0bfadc2011
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 6m27s
[CLAUDE] Contract: K8-blocker Lines-editor KHKK — gan hang muc SP-002 cho dong (command hua-trong-comment chua tung land)
- Dry-run K8 bat TRUOC gio chay: auto-gen line moi CatalogEntryId=null + comment hen "UpdateContractSigningPlanLineCommand" (K4b) nhung K4b that ship ?group= => 0 impl/0 route/0 FE; submit-guard va-5 chan null => MOI phieu KHKK tao sau K2 ket Nhap vinh vien (dung cho cicd-K2 khai "chan-ly-rong")
- BE: UpdateContractSigningPlanLineCommand(PlanId,LineId,CatalogEntryId) — EnsureDraftEditable + rao ContractId!=null 409 (gate F-6) + fail-fast entry song/IsActive/dung-nhom 409 + denorm TenHangMuc + changelog EntityType.Line EntityId=line.Id + ten NCC vao Summary (gate F-1)
- API: PUT /contract-signing-plans/{id}/lines/{lineId} policy KeHoachKyKet.Update + UpdateSigningPlanLineBody
- FE x2 app KhkkDetailPage (SHA-pair 0d6147d0): select gan tai bang (Nhap/TraLai, khoa dong da bac cau HD) + option-fallback giu hang-muc-da-luu khi vang options (gate F-2, 3 ca loading/error/ngung-hieu-luc) + dong loi query + amber nhom-0-hang-muc (F-3) + aria-label per-dong (F-8)
- Test +5 Fact: duong gan->submit-QUA guard that · khac-nhom 409 · phase 409 · IsActive=false 409 · gan-DE doi ca Id lan snapshot (gate F-4)
- Gate PASS-WITH-FLAGS-8/0-blocker — disposition tung dong trong sub-reviewer-gate-lineeditor.md; F-5/F-7 ghi no cung goi RowVersion/unique voi no K7 race-2-request
- scripts/backup-sql.ps1 default D:\ -> C:\ (VPS khong co o D — do that B0)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-01 17:08: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 "D:\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