fix(备份): 防止恢复脚本覆盖数据库并返回失败码

修复根目录 README 的失效文档链接,改为现有 T+ 本地恢复手册。\n恢复脚本移除 RESTORE WITH REPLACE,默认不覆盖已有数据库;成功和失败均写入结果文件,失败显式返回非零退出码,并统一释放数据库连接。\n\n影响范围:项目导航文档与两个本地 SQL Server 恢复辅助脚本。\n\nCo-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
liuwenxin committed 2026-11-06 15:36:39 +08:00
1 parent a4794489b1
commit 35fea3802f
3 files changed
+51 -2

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
# restore_run.ps1 - 独立进程执行 RESTORE,默认不覆盖已有数据库
if (-not $env:PAYROLL_RESTORE_CONNECTION_STRING) { throw "PAYROLL_RESTORE_CONNECTION_STRING is required" }
$connStr = $env:PAYROLL_RESTORE_CONNECTION_STRING
$c = New-Object System.Data.Odbc.OdbcConnection $connStr
$cmd = $null
try {
$c.Open()
$cmd = $c.CreateCommand()
$cmd.CommandTimeout = 14400
$cmd.CommandText = @"
RESTORE DATABASE [UFTData472115_000001]
FROM DISK = '\\192.168.1.170\dbbak\ceshi20261026.bak'
WITH MOVE 'MsSql' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\UFTData472115_000001.mdf',
MOVE 'MsSql_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\UFTData472115_000001_log.ldf',
RECOVERY, STATS = 10
"@
$cmd.ExecuteNonQuery() | Out-Null
"RESTORE-DONE-OK" | Out-File 'D:\work\code\PayrollManagementSystem\db\restore_result.txt' -Encoding ascii
exit 0
} catch {
$message = $_.Exception.Message
if ($_.Exception.InnerException) { $message = $_.Exception.InnerException.Message }
("RESTORE-FAILED: " + $message) | Out-File 'D:\work\code\PayrollManagementSystem\db\restore_result.txt' -Encoding ascii
exit 1
} finally {
if ($cmd) { $cmd.Dispose() }
if ($c) { $c.Close(); $c.Dispose() }
}
+19
View File
@@ -0,0 +1,19 @@
if (-not $env:PAYROLL_RESTORE_CONNECTION_STRING) { throw "PAYROLL_RESTORE_CONNECTION_STRING is required" }
$connStr = $env:PAYROLL_RESTORE_CONNECTION_STRING
$c = New-Object System.Data.Odbc.OdbcConnection $connStr
$cmd = $null
try {
$c.Open()
$cmd = $c.CreateCommand()
$cmd.CommandTimeout = 14400
$cmd.CommandText = "RESTORE DATABASE [UFTData472115_000001] FROM DISK = 'C:\baktmp\ceshi20261026.bak' WITH MOVE 'MsSql' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\UFTData472115_000001.mdf', MOVE 'MsSql_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\UFTData472115_000001_log.ldf', RECOVERY, STATS = 10"
$cmd.ExecuteNonQuery() | Out-Null
"RESTORE-DONE-OK" | Out-File "D:\work\code\PayrollManagementSystem\db\restore_result.txt" -Encoding ascii
exit 0
} catch {
("RESTORE-FAILED: " + $_.Exception.Message) | Out-File "D:\work\code\PayrollManagementSystem\db\restore_result.txt" -Encoding ascii
exit 1
} finally {
if ($cmd) { $cmd.Dispose() }
if ($c) { $c.Close(); $c.Dispose() }
}