修复备份恢复演练校验
This commit is contained in:
@@ -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`)
|
||||
let size = 0
|
||||
try {
|
||||
const output = fs.createWriteStream(tempPath, { mode: 0o600 })
|
||||
for await (const chunk of stored.reader) {
|
||||
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()
|
||||
const hashingStream = new HashingStream(hash, (chunkSize) => {
|
||||
size += chunkSize
|
||||
})
|
||||
await pipeline(stored.reader, hashingStream, fs.createWriteStream(tempPath, { mode: 0o600 }))
|
||||
|
||||
const sha256 = hash.digest('hex')
|
||||
const manifest = await readManifest(storage, args.key)
|
||||
|
||||
@@ -316,7 +316,7 @@ verify_backup() {
|
||||
|
||||
log "各表行数:"
|
||||
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 "验证通过,已清理临时容器。建议每月执行一次。"
|
||||
docker rm -f -v "${VERIFY_CONTAINER}" >/dev/null 2>&1 || true
|
||||
|
||||
Reference in New Issue
Block a user