fix(api): восстановить разделы PostgreSQL в одной транзакции
This commit is contained in:
1 parent
c24ad7810c
commit
f3e205950f
10 files changed
+261
-10
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { randomUUID } from "node:crypto"
|
||||
import { spawn } from "node:child_process"
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises"
|
||||
import { chmod, mkdir, rm, writeFile } from "node:fs/promises"
|
||||
import os from "node:os"
|
||||
import path from "node:path"
|
||||
import { executeSystemDatabaseRestore, validateSystemDatabaseRestoreArchive, type SystemDatabaseRestoreOutcome } from "./system-database-restore-execution.js"
|
||||
@@ -11,6 +11,7 @@ import { executeDatabaseOperation, type DatabaseOperationWarnings } from "./syst
|
||||
import { restartSchedulerAfterDatabaseOperation, stopSchedulerForDatabaseOperation } from "./scheduler.js"
|
||||
import { pauseRipeBackgroundWork, resumeRipeBackgroundWork } from "./traffic-flow-ripe.js"
|
||||
import { invalidateSystemDatabaseCaches } from "./system-database-cache.js"
|
||||
import { restorePartitionedDatabase } from "./system-database-partition-restore.js"
|
||||
import {
|
||||
restartTrafficFlowListenerAfterDatabaseOperation,
|
||||
stopTrafficFlowListenerForDatabaseOperation,
|
||||
@@ -78,12 +79,18 @@ export async function restoreSystemDatabaseBackup(buffer: Buffer): Promise<Syste
|
||||
return await withDatabaseOperation(() => executeSystemDatabaseRestore(buffer, env.DATABASE_URL, {
|
||||
allocate: async () => {
|
||||
const tempDir = path.join(os.tmpdir(), "mmapp-db-restore")
|
||||
await mkdir(tempDir, { recursive: true })
|
||||
await mkdir(tempDir, { recursive: true, mode: 0o700 })
|
||||
await chmod(tempDir, 0o700)
|
||||
return path.join(tempDir, `restore-${randomUUID()}.dump`)
|
||||
},
|
||||
write: (file, data) => writeFile(file, data),
|
||||
run: async args => { await spawnCollected("pg_restore", args) },
|
||||
remove: file => rm(file, { force: true }),
|
||||
write: (file, data) => writeFile(file, data, { mode: 0o600 }),
|
||||
run: async args => {
|
||||
await restorePartitionedDatabase(args[args.length - 1], env.DATABASE_URL, {
|
||||
command: spawnCollected,
|
||||
prepareSql: file => writeFile(file, "", { mode: 0o600 }),
|
||||
})
|
||||
},
|
||||
remove: async file => { await Promise.all([rm(file, { force: true }), rm(`${file}.sql`, { force: true })]) },
|
||||
invalidate: invalidateSystemDatabaseCaches,
|
||||
}))
|
||||
}
|
||||
Reference in new issue
Block a user