mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
export to a temporary directory instead
This commit is contained in:
parent
105d5c6ad9
commit
5d35e61937
|
@ -167,6 +167,7 @@
|
|||
"sshpk": "1.17.0",
|
||||
"swagger-ui-express": "5.0.0",
|
||||
"syslog-client": "1.1.1",
|
||||
"tmp-promise": "3.0.3",
|
||||
"typedi": "catalog:",
|
||||
"uuid": "catalog:",
|
||||
"validator": "13.7.0",
|
||||
|
|
|
@ -3,6 +3,7 @@ import * as assert from 'assert/strict';
|
|||
import fs from 'fs';
|
||||
import { join } from 'path';
|
||||
import Container from 'typedi';
|
||||
import { dir as tmpDir } from 'tmp-promise';
|
||||
|
||||
import { jsonColumnType } from '@/databases/entities/abstract-entity';
|
||||
import { BaseCommand } from '../base-command';
|
||||
|
@ -34,8 +35,8 @@ export class ExportAllCommand extends BaseCommand {
|
|||
columns: v.columns,
|
||||
}));
|
||||
|
||||
const backupPath = '/tmp/backup';
|
||||
await fs.promises.mkdir(backupPath, { recursive: true });
|
||||
const { path: tempBackupDir } = await tmpDir({});
|
||||
await fs.promises.mkdir(tempBackupDir, { recursive: true });
|
||||
|
||||
for (const { name: tableName, columns } of tables) {
|
||||
const totalRowsCount = await connection
|
||||
|
@ -43,7 +44,7 @@ export class ExportAllCommand extends BaseCommand {
|
|||
.then((rows: Array<{ count: number }>) => rows[0].count);
|
||||
if (totalRowsCount === 0) continue;
|
||||
|
||||
const stream = fs.createWriteStream(join(backupPath, `${tableName}.jsonl`));
|
||||
const stream = fs.createWriteStream(join(tempBackupDir, `${tableName}.jsonl`));
|
||||
|
||||
let cursor = 0;
|
||||
const batchSize = 10;
|
||||
|
@ -87,10 +88,14 @@ export class ExportAllCommand extends BaseCommand {
|
|||
assert.ok(lastExecutedMigration, 'should have been run by db.ts');
|
||||
|
||||
await fs.promises.writeFile(
|
||||
join(backupPath, 'lastMigration'),
|
||||
join(tempBackupDir, 'lastMigration'),
|
||||
lastExecutedMigration.name,
|
||||
'utf8',
|
||||
);
|
||||
|
||||
console.log(`data exported to ${tempBackupDir}`);
|
||||
|
||||
// TODO: clean up temp dir
|
||||
}
|
||||
|
||||
async catch(error: Error) {
|
||||
|
|
|
@ -929,6 +929,9 @@ importers:
|
|||
syslog-client:
|
||||
specifier: 1.1.1
|
||||
version: 1.1.1
|
||||
tmp-promise:
|
||||
specifier: 3.0.3
|
||||
version: 3.0.3
|
||||
typedi:
|
||||
specifier: 'catalog:'
|
||||
version: 0.10.0(patch_hash=sk6omkefrosihg7lmqbzh7vfxe)
|
||||
|
@ -11600,10 +11603,6 @@ packages:
|
|||
resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==}
|
||||
engines: {node: '>=0.6.0'}
|
||||
|
||||
tmp@0.2.1:
|
||||
resolution: {integrity: sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==}
|
||||
engines: {node: '>=8.17.0'}
|
||||
|
||||
tmp@0.2.3:
|
||||
resolution: {integrity: sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==}
|
||||
engines: {node: '>=14.14'}
|
||||
|
@ -25348,16 +25347,12 @@ snapshots:
|
|||
|
||||
tmp-promise@3.0.3:
|
||||
dependencies:
|
||||
tmp: 0.2.1
|
||||
tmp: 0.2.3
|
||||
|
||||
tmp@0.0.33:
|
||||
dependencies:
|
||||
os-tmpdir: 1.0.2
|
||||
|
||||
tmp@0.2.1:
|
||||
dependencies:
|
||||
rimraf: 3.0.2
|
||||
|
||||
tmp@0.2.3: {}
|
||||
|
||||
tmpl@1.0.5: {}
|
||||
|
|
Loading…
Reference in a new issue