@ps-aux/nodebup 0.9.4 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bup/pg/PgBackupController.js +4 -4
- package/lib/ctx/ContextSymbols.js +1 -7
- package/lib/fs/Fs.test.js +0 -3
- package/lib/log/logging.js +10 -6
- package/lib/log/logging.spec.js +10 -0
- package/lib/storage/restic/ResticClient.js +5 -5
- package/lib/tools/compression/Zipper.js +15 -6
- package/lib/tools/compression/Zipper.test.js +17 -13
- package/package.json +2 -1
- package/lib/types.js +0 -5
@@ -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,17 +105,17 @@ 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
|
-
this.log.debug('Will run psql import from %s', outFile); // Don't forget that this itself might be run in docker
|
118
|
+
this.log.debug('Will run psql import from %s', outFile.str()); // Don't forget that this itself might be run in docker
|
119
119
|
// therefore volume mounts are not usable (will apply to the location at host)
|
120
120
|
|
121
121
|
this.sh.exec(`docker run --network host -i ` + `postgres:${version} ` + `psql ${pgUrl} -v ON_ERROR_STOP=0 < ${outFile.str()}`);
|
@@ -3,13 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
7
|
-
const Log_ = Symbol.for('Log');
|
8
|
-
exports.Log_ = Log_;
|
9
|
-
const TaskConfig_ = Symbol.for('config.Tasks');
|
10
|
-
exports.TaskConfig_ = TaskConfig_;
|
11
|
-
const StorageConfig_ = Symbol.for('config.Storage');
|
12
|
-
exports.StorageConfig_ = StorageConfig_;
|
6
|
+
exports.Inputs_ = exports.AppConfig_ = void 0;
|
13
7
|
const AppConfig_ = Symbol.for('config.app');
|
14
8
|
exports.AppConfig_ = AppConfig_;
|
15
9
|
const Inputs_ = Symbol.for('cmd.input');
|
package/lib/fs/Fs.test.js
CHANGED
@@ -7,12 +7,9 @@ var _Path = require("./path/Path");
|
|
7
7
|
it.skip('withTmpDir', async () => {
|
8
8
|
const fs = new _Fs.Fs(_Path.AbsPath.from(__dirname));
|
9
9
|
await fs.inTmpDir('foo', async () => {
|
10
|
-
console.log('before');
|
11
10
|
const wait = new Promise((res, rej) => {
|
12
11
|
setTimeout(res, 1000);
|
13
12
|
});
|
14
13
|
await wait;
|
15
|
-
console.log('after');
|
16
14
|
});
|
17
|
-
console.log('done');
|
18
15
|
});
|
package/lib/log/logging.js
CHANGED
@@ -13,15 +13,19 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
13
13
|
const level = process.env.NODEBUP_LOG_LEVEL || 'trace';
|
14
14
|
const root = (0, _pino.default)({
|
15
15
|
name: 'root',
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
level,
|
17
|
+
prettyPrint: true // TODO deprecated but other options don't work
|
18
|
+
// Must be used as string. For some reason does not work as transport.
|
19
|
+
// 1. No logging in Jest
|
20
|
+
// 2. Not logging when run as CLI app
|
21
|
+
|
22
|
+
} // stream
|
23
|
+
);
|
21
24
|
|
22
25
|
const makeLog = name => {
|
23
26
|
return root.child({
|
24
|
-
name
|
27
|
+
name,
|
28
|
+
level
|
25
29
|
});
|
26
30
|
}; // TODO make type narrower
|
27
31
|
|
@@ -31,7 +31,7 @@ class ResticClient {
|
|
31
31
|
_defineProperty(this, "log", (0, _logging.classObjLog)(this));
|
32
32
|
|
33
33
|
_defineProperty(this, "prepareRepo", () => {
|
34
|
-
this.log.info(
|
34
|
+
this.log.info('Preparing a restic repo at %s', this.url);
|
35
35
|
this.shell.exec(`restic init`, {
|
36
36
|
env: this.env()
|
37
37
|
});
|
@@ -44,7 +44,7 @@ class ResticClient {
|
|
44
44
|
});
|
45
45
|
|
46
46
|
_defineProperty(this, "backup", (cwd, from, tags = []) => {
|
47
|
-
this.log.debug(
|
47
|
+
this.log.debug('Running backup for repo=%s', this.url);
|
48
48
|
let cmd = `restic backup ${from.str()}`;
|
49
49
|
tags.forEach(t => {
|
50
50
|
cmd += ` --tag=${t}`;
|
@@ -56,14 +56,14 @@ class ResticClient {
|
|
56
56
|
});
|
57
57
|
|
58
58
|
_defineProperty(this, "restore", (to, snapshotId = 'latest') => {
|
59
|
-
this.log.debug('Running restore for repo
|
59
|
+
this.log.debug('Running restore for repo=%s', this.url);
|
60
60
|
this.shell.exec(`restic restore ${snapshotId} --target ${to.str()}`, {
|
61
61
|
env: this.env()
|
62
62
|
});
|
63
63
|
});
|
64
64
|
|
65
65
|
_defineProperty(this, "forget", () => {
|
66
|
-
this.log.debug(
|
66
|
+
this.log.debug('Pruning repo=%s', this.url);
|
67
67
|
const cfg = {
|
68
68
|
hourly: 6,
|
69
69
|
daily: 7,
|
@@ -77,7 +77,7 @@ class ResticClient {
|
|
77
77
|
});
|
78
78
|
|
79
79
|
_defineProperty(this, "snapshots", () => {
|
80
|
-
this.log.debug(
|
80
|
+
this.log.debug('Listing snapshots of repo=%', this.url);
|
81
81
|
const out = this.shell.execAndReturnString(`restic snapshots --json`, {
|
82
82
|
env: this.env()
|
83
83
|
});
|
@@ -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.6",
|
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"
|