@ps-aux/nodebup 0.9.5 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -89,7 +89,7 @@ let PgBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.m
|
|
89
89
|
f.end();
|
90
90
|
this.log.info('Compressing');
|
91
91
|
const zipOutputName = `pg-backup-${this.now()}.zip`;
|
92
|
-
this.zip.zipDir(outputDir, outputDir.resolve(zipOutputName));
|
92
|
+
await this.zip.zipDir(outputDir, outputDir.resolve(zipOutputName));
|
93
93
|
this.fs.rmFile(dumpOut);
|
94
94
|
this.log.info('Uploading');
|
95
95
|
storage.store(_Path.AbsPath.from(dir));
|
@@ -105,14 +105,14 @@ let PgBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.m
|
|
105
105
|
|
106
106
|
parseConnectionUrl(pgUrl);
|
107
107
|
this.log.info(`Restoring Postgres database, version=${version}`);
|
108
|
-
await this.fs.inTmpDir('pg-restore', dirStr => {
|
108
|
+
await this.fs.inTmpDir('pg-restore', async dirStr => {
|
109
109
|
const dir = _Path.AbsPath.from(dirStr);
|
110
110
|
|
111
111
|
storage.restore(dir); // TODO check if the dir contains the with the expected name
|
112
112
|
// TODO add e2e test for docker
|
113
113
|
|
114
114
|
const zipFile = this.fs.listFiles(dir)[0];
|
115
|
-
this.zip.unzipDir(zipFile, dir);
|
115
|
+
await this.zip.unzipDir(zipFile, dir);
|
116
116
|
this.fs.rmFile(zipFile);
|
117
117
|
const outFile = this.fs.listFiles(dir)[0];
|
118
118
|
this.log.debug('Will run psql import from %s', outFile.str()); // Don't forget that this itself might be run in docker
|
package/lib/log/logging.js
CHANGED
@@ -7,19 +7,20 @@ exports.makeLog = exports.classObjLog = void 0;
|
|
7
7
|
|
8
8
|
var _pino = _interopRequireDefault(require("pino"));
|
9
9
|
|
10
|
+
var _pinoPretty = _interopRequireDefault(require("pino-pretty"));
|
11
|
+
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
13
|
|
12
|
-
// TODO set from config
|
14
|
+
// TODO set from the config
|
13
15
|
const level = process.env.NODEBUP_LOG_LEVEL || 'trace';
|
16
|
+
const sync = process.env.TS_JEST === '1';
|
17
|
+
const stream = (0, _pinoPretty.default)({
|
18
|
+
sync
|
19
|
+
});
|
14
20
|
const root = (0, _pino.default)({
|
15
21
|
name: 'root',
|
16
|
-
prettyPrint: true,
|
17
|
-
// - This will lead to problems with logging to stdout
|
18
|
-
// 1. No logging in Jest
|
19
|
-
// 2. Not logging when run as CLI app
|
20
|
-
// transport: { target: 'pino-pretty' },
|
21
22
|
level
|
22
|
-
});
|
23
|
+
}, stream);
|
23
24
|
|
24
25
|
const makeLog = name => {
|
25
26
|
return root.child({
|
@@ -11,6 +11,10 @@ var _inversify = require("inversify");
|
|
11
11
|
|
12
12
|
var _logging = require("../../log/logging");
|
13
13
|
|
14
|
+
var _unzipper = _interopRequireDefault(require("unzipper"));
|
15
|
+
|
16
|
+
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
17
|
+
|
14
18
|
var _dec, _class;
|
15
19
|
|
16
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -21,17 +25,22 @@ let Zipper = (_dec = (0, _inversify.injectable)(), _dec(_class = class Zipper {
|
|
21
25
|
constructor() {
|
22
26
|
_defineProperty(this, "log", (0, _logging.classObjLog)(this));
|
23
27
|
|
24
|
-
_defineProperty(this, "zipDir", (dir, to) => {
|
25
|
-
this.log.
|
28
|
+
_defineProperty(this, "zipDir", async (dir, to) => {
|
29
|
+
this.log.trace(`Zipping %s to %s`, dir.str(), to.str());
|
26
30
|
const z = new _admZip.default();
|
27
31
|
z.addLocalFolder(dir.str());
|
28
32
|
z.writeZip(to.str());
|
29
33
|
});
|
30
34
|
|
31
|
-
_defineProperty(this, "unzipDir", (zipFile, toDir) => {
|
32
|
-
this.log.
|
33
|
-
|
34
|
-
|
35
|
+
_defineProperty(this, "unzipDir", async (zipFile, toDir) => {
|
36
|
+
this.log.trace(`Unzipping %s to %s`, zipFile.str(), toDir.str());
|
37
|
+
return new Promise((res, rej) => {
|
38
|
+
_nodeFs.default.createReadStream(zipFile.str()).pipe(_unzipper.default.Extract({
|
39
|
+
path: toDir.str()
|
40
|
+
})).on('close', () => {
|
41
|
+
res();
|
42
|
+
}).on('error', rej);
|
43
|
+
});
|
35
44
|
});
|
36
45
|
}
|
37
46
|
|
@@ -6,17 +6,21 @@ var _Path = require("../../fs/path/Path");
|
|
6
6
|
|
7
7
|
var _testHelper = require("../../../test/testHelper");
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
var _test = require("../../../test");
|
10
|
+
|
11
|
+
describe('zip', () => {
|
12
|
+
afterEach(() => {
|
13
|
+
(0, _testHelper.cleanTestDataDir)();
|
14
|
+
});
|
15
|
+
it('zip and unzip', async () => {
|
16
|
+
const z = new _Zipper.Zipper();
|
17
|
+
const out = (0, _test.testdataDirPath)('out.zip');
|
18
|
+
|
19
|
+
const dir = _Path.AbsPath.from(__dirname).resolve('../../../test/foo');
|
20
|
+
|
21
|
+
await z.zipDir(dir, out);
|
22
|
+
const extDir = (0, _test.testdataDirPath)('foo-out');
|
23
|
+
await z.unzipDir(out, extDir);
|
24
|
+
(0, _testHelper.expectDirsToBeTheSame)(dir.str(), extDir.str());
|
25
|
+
});
|
22
26
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ps-aux/nodebup",
|
3
|
-
"version": "0.9.
|
3
|
+
"version": "0.9.7",
|
4
4
|
"description": "",
|
5
5
|
"module": "lib/index.js",
|
6
6
|
"main": "lib/index.js",
|
@@ -90,6 +90,7 @@
|
|
90
90
|
"pino-pretty": "^9.1.1",
|
91
91
|
"ramda": "^0.27.1",
|
92
92
|
"reflect-metadata": "^0.1.13",
|
93
|
+
"unzipper": "^0.10.11",
|
93
94
|
"wait-on": "^6.0.0",
|
94
95
|
"yaml": "^1.10.2",
|
95
96
|
"yargs": "^17.3.1"
|