@ps-aux/nodebup 0.7.1 → 0.7.2
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.
@@ -17,6 +17,8 @@ var _Path = require("../../fs/path/Path");
|
|
17
17
|
|
18
18
|
var _StorageBackendProvider = require("../../storage/StorageBackendProvider");
|
19
19
|
|
20
|
+
var _Zipper = require("../../tools/compression/Zipper");
|
21
|
+
|
20
22
|
var _dec, _dec2, _dec3, _class, _class2, _temp;
|
21
23
|
|
22
24
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
@@ -35,16 +37,17 @@ const parseConnectionUrl = url => {
|
|
35
37
|
};
|
36
38
|
};
|
37
39
|
|
38
|
-
let PgBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof _StorageBackendProvider.StorageBackendProvider === "undefined" ? Object : _StorageBackendProvider.StorageBackendProvider, typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell]), _dec(_class = _dec2(_class = _dec3(_class = (_temp = _class2 = class PgBackupController {
|
40
|
+
let PgBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _Fs.Fs === "undefined" ? Object : _Fs.Fs, typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger, typeof _StorageBackendProvider.StorageBackendProvider === "undefined" ? Object : _StorageBackendProvider.StorageBackendProvider, typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell, typeof _Zipper.Zipper === "undefined" ? Object : _Zipper.Zipper]), _dec(_class = _dec2(_class = _dec3(_class = (_temp = _class2 = class PgBackupController {
|
39
41
|
constructor( // private gpg: Gpg,
|
40
42
|
// private ssh: SshKeyManager,
|
41
43
|
fs, // private fsSyncer: FsSyncer,
|
42
44
|
log, storageBackendProvider, // @inject(AppConfig_) private cfg: Config,
|
43
|
-
sh) {
|
45
|
+
sh, zip) {
|
44
46
|
this.fs = fs;
|
45
47
|
this.log = log;
|
46
48
|
this.storageBackendProvider = storageBackendProvider;
|
47
49
|
this.sh = sh;
|
50
|
+
this.zip = zip;
|
48
51
|
|
49
52
|
_defineProperty(this, "now", () => {
|
50
53
|
const d = new Date();
|
@@ -54,6 +57,8 @@ let PgBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.m
|
|
54
57
|
|
55
58
|
_defineProperty(this, "getVersion", version => version || PgBackupController.defaultPgVersion);
|
56
59
|
|
60
|
+
_defineProperty(this, "outFileName", 'backup.sql');
|
61
|
+
|
57
62
|
_defineProperty(this, "backup", ({
|
58
63
|
pgUrl,
|
59
64
|
pgVersion
|
@@ -71,12 +76,11 @@ let PgBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.m
|
|
71
76
|
const bashCmds = [`echo "*:*:*:*:${pass}" > ~/.pgpass`, `chmod 400 ~/.pgpass`, `pg_dumpall -d ${pgUrl}`]; // TODO improve sh logging to avoid showing secrets
|
72
77
|
|
73
78
|
const b = this.sh.execAndReturnBuffer(`docker run --network host ` + `postgres:${version} ` + `bash -c '${bashCmds.join(' && ')}'`);
|
74
|
-
const
|
75
|
-
const dumpOut = outputDir.resolve(outFileName);
|
79
|
+
const dumpOut = outputDir.resolve(this.outFileName);
|
76
80
|
this.fs.writeFile(dumpOut, b);
|
77
81
|
this.log.info('Compressing');
|
78
82
|
const zipOutputName = `pg-backup-${this.now()}.zip`;
|
79
|
-
this.
|
83
|
+
this.zip.zipDir(outputDir, outputDir.resolve(zipOutputName));
|
80
84
|
this.fs.rmFile(dumpOut);
|
81
85
|
this.log.info('Uploading');
|
82
86
|
storage.store(_Path.AbsPath.from(dir));
|
@@ -95,10 +99,10 @@ let PgBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.m
|
|
95
99
|
this.fs.inTmpDir('pg-restore', dirStr => {
|
96
100
|
const dir = _Path.AbsPath.from(dirStr);
|
97
101
|
|
98
|
-
storage.restore(dir);
|
99
|
-
const zipFile = this.fs.listFiles(dir)[0]; //
|
102
|
+
storage.restore(dir); // TODO check if the dir contains the with the expected name
|
100
103
|
|
101
|
-
|
104
|
+
const zipFile = this.fs.listFiles(dir)[0];
|
105
|
+
this.zip.unzipDir(zipFile, dir);
|
102
106
|
this.fs.rmFile(zipFile);
|
103
107
|
const outFile = this.fs.listFiles(dir)[0];
|
104
108
|
this.sh.exec(`docker run --network host ` + `-v "${outFile.str()}":/pg/import.sql -w /pg ` + `postgres:${version} ` + `psql ${pgUrl} -v ON_ERROR_STOP=0 -f import.sql`);
|
@@ -106,5 +110,5 @@ let PgBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.m
|
|
106
110
|
});
|
107
111
|
}
|
108
112
|
|
109
|
-
}, _defineProperty(_class2, "defaultPgVersion", '14.2'),
|
113
|
+
}, _defineProperty(_class2, "defaultPgVersion", '14.2'), _temp)) || _class) || _class) || _class);
|
110
114
|
exports.PgBackupController = PgBackupController;
|
package/lib/ctx/Context.js
CHANGED
@@ -39,6 +39,8 @@ var _StorageConfigProvider = require("../storage/StorageConfigProvider");
|
|
39
39
|
|
40
40
|
var _PgBackupController = require("../bup/pg/PgBackupController");
|
41
41
|
|
42
|
+
var _Zipper = require("../tools/compression/Zipper");
|
43
|
+
|
42
44
|
const createContext = (cfg, inp) => {
|
43
45
|
const c = new _inversify.Container();
|
44
46
|
c.bind(_ContextSymbols.AppConfig_).toConstantValue(cfg);
|
@@ -47,7 +49,7 @@ const createContext = (cfg, inp) => {
|
|
47
49
|
c.bind(_ContextSymbols.Log_).toConstantValue(log);
|
48
50
|
c.bind(_AppLogger.AppLogger).toConstantValue(log);
|
49
51
|
c.bind(_Fs.Fs).toConstantValue(new _Fs.Fs(cfg.pwd, log));
|
50
|
-
const self = [_Gpg.Gpg, _Shell.Shell, _FsSyncer.FsSyncer, _SshKeyManager.SshKeyManager, _StorageBackendProvider.StorageBackendProvider, _StorageConfigProvider.StorageConfigProvider, _ResticClientFactory.ResticClientFactory, _AggregateBackupController.AggregateBackupController, _ResticController.ResticController, _B2CredentialsProvider.B2CredentialsProvider, _RCloneClientFactory.RCloneClientFactory, _DataBackupController.DataBackupController, _PgBackupController.PgBackupController];
|
52
|
+
const self = [_Gpg.Gpg, _Shell.Shell, _FsSyncer.FsSyncer, _SshKeyManager.SshKeyManager, _StorageBackendProvider.StorageBackendProvider, _StorageConfigProvider.StorageConfigProvider, _ResticClientFactory.ResticClientFactory, _AggregateBackupController.AggregateBackupController, _ResticController.ResticController, _B2CredentialsProvider.B2CredentialsProvider, _RCloneClientFactory.RCloneClientFactory, _DataBackupController.DataBackupController, _PgBackupController.PgBackupController, _Zipper.Zipper];
|
51
53
|
self.forEach(s => c.bind(s).toSelf());
|
52
54
|
return c;
|
53
55
|
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Zipper = void 0;
|
7
|
+
|
8
|
+
var _admZip = _interopRequireDefault(require("adm-zip"));
|
9
|
+
|
10
|
+
var _inversify = require("inversify");
|
11
|
+
|
12
|
+
var _AppLogger = require("../../log/AppLogger");
|
13
|
+
|
14
|
+
var _dec, _dec2, _dec3, _class;
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
18
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
19
|
+
|
20
|
+
let Zipper = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _AppLogger.AppLogger === "undefined" ? Object : _AppLogger.AppLogger]), _dec(_class = _dec2(_class = _dec3(_class = class Zipper {
|
21
|
+
constructor(log) {
|
22
|
+
this.log = log;
|
23
|
+
|
24
|
+
_defineProperty(this, "zipDir", (dir, to) => {
|
25
|
+
this.log.debug(`Zipping ${dir} to ${to}`);
|
26
|
+
const z = new _admZip.default();
|
27
|
+
z.addLocalFolder(dir.str());
|
28
|
+
z.writeZip(to.str());
|
29
|
+
});
|
30
|
+
|
31
|
+
_defineProperty(this, "unzipDir", (zipFile, toDir) => {
|
32
|
+
this.log.debug(`Unzipping ${zipFile} to ${toDir}`);
|
33
|
+
const z = new _admZip.default(zipFile.str());
|
34
|
+
z.extractAllTo(toDir.str());
|
35
|
+
});
|
36
|
+
}
|
37
|
+
|
38
|
+
}) || _class) || _class) || _class);
|
39
|
+
exports.Zipper = Zipper;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _Zipper = require("./Zipper");
|
4
|
+
|
5
|
+
var _Path = require("../../fs/path/Path");
|
6
|
+
|
7
|
+
var _testHelper = require("../../../test/testHelper");
|
8
|
+
|
9
|
+
var _AppLogger = require("../../log/AppLogger");
|
10
|
+
|
11
|
+
it('zip', () => {
|
12
|
+
const z = new _Zipper.Zipper(new _AppLogger.AppLogger());
|
13
|
+
|
14
|
+
const out = _Path.AbsPath.from(__dirname).resolve('../../test-data/out.zip');
|
15
|
+
|
16
|
+
const dir = _Path.AbsPath.from(__dirname).resolve('../../../test/foo');
|
17
|
+
|
18
|
+
z.zipDir(dir, out);
|
19
|
+
|
20
|
+
const extDir = _Path.AbsPath.from(__dirname).resolve('../../test-data/foo-out');
|
21
|
+
|
22
|
+
z.unzipDir(out, extDir);
|
23
|
+
(0, _testHelper.expectDirsToBeTheSame)(dir.str(), extDir.str());
|
24
|
+
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ps-aux/nodebup",
|
3
|
-
"version": "0.7.
|
3
|
+
"version": "0.7.2",
|
4
4
|
"description": "",
|
5
5
|
"module": "lib/index.js",
|
6
6
|
"main": "lib/index.js",
|
@@ -80,6 +80,7 @@
|
|
80
80
|
"@hapi/joi": "^17.1.1",
|
81
81
|
"@ps-aux/nclif": "^0.0.7-alpha.1",
|
82
82
|
"@types/hapi__joi": "^17.1.8",
|
83
|
+
"adm-zip": "^0.5.9",
|
83
84
|
"axios": "^0.24.0",
|
84
85
|
"handlebars": "^4.7.7",
|
85
86
|
"ini": "^2.0.0",
|