修复备份恢复演练校验

This commit is contained in:
yml2213
2026-08-23 15:01:11 +08:00
parent f237a6f6ce
commit ad59066637
2 changed files with 4 additions and 17 deletions
+3 -16
View File
@@ -417,23 +417,10 @@ async function downloadToStdout(storage: ObjectStorage, args: BackupCliArgs): Pr
const tempPath = path.join('/tmp', `order-site-backup-${process.pid}-${Date.now()}.dump`) const tempPath = path.join('/tmp', `order-site-backup-${process.pid}-${Date.now()}.dump`)
let size = 0 let size = 0
try { try {
const output = fs.createWriteStream(tempPath, { mode: 0o600 }) const hashingStream = new HashingStream(hash, (chunkSize) => {
for await (const chunk of stored.reader) { size += chunkSize
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)
hash.update(buffer)
size += buffer.length
if (!output.write(buffer)) {
await new Promise<void>((resolve, reject) => {
output.once('drain', resolve)
output.once('error', reject)
})
}
}
await new Promise<void>((resolve, reject) => {
output.once('close', resolve)
output.once('error', reject)
output.end()
}) })
await pipeline(stored.reader, hashingStream, fs.createWriteStream(tempPath, { mode: 0o600 }))
const sha256 = hash.digest('hex') const sha256 = hash.digest('hex')
const manifest = await readManifest(storage, args.key) const manifest = await readManifest(storage, args.key)
+1 -1
View File
@@ -316,7 +316,7 @@ verify_backup() {
log "各表行数:" log "各表行数:"
docker exec "${cid}" psql -U postgres -d order_site -At -F '=' \ docker exec "${cid}" psql -U postgres -d order_site -At -F '=' \
-c "SELECT format('SELECT %L, count(*) FROM %I;', tablename) FROM pg_tables WHERE schemaname = 'public' ORDER BY tablename \\gexec" -c "SELECT tablename, (xpath('/row/count/text()', query_to_xml(format('SELECT count(*) AS count FROM %I.%I', schemaname, tablename), true, false, '')))[1]::text::bigint FROM pg_tables WHERE schemaname = 'public' ORDER BY tablename"
log "验证通过,已清理临时容器。建议每月执行一次。" log "验证通过,已清理临时容器。建议每月执行一次。"
docker rm -f -v "${VERIFY_CONTAINER}" >/dev/null 2>&1 || true docker rm -f -v "${VERIFY_CONTAINER}" >/dev/null 2>&1 || true