@ps-aux/nodebup 0.9.9 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -76,21 +76,13 @@ let PgBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.m
76
76
  await this.fs.inTmpDir('pg-backup', async dir => {
77
77
  const outputDir = _Path.AbsPath.from(dir);
78
78
 
79
- this.log.info('Dumping database to a file');
79
+ this.log.info('Processing Postgres backup');
80
80
  const bashCmds = [`echo "*:*:*:*:${pass}" > ~/.pgpass`, `chmod 400 ~/.pgpass`, `pg_dumpall -d ${pgUrl}`]; // Don't forget that this itself might be run in docker
81
81
  // therefore volume mounts are not usable (will apply to the location at host)
82
82
 
83
- const dumpOut = outputDir.resolve(this.outFileName);
84
- const f = this.fs.writeStream(dumpOut);
85
- await this.sh.asyncExec(`docker run --rm --network host ` + `postgres:${version} ` + `bash -c '${bashCmds.join(' && ')}'`, // f.write
86
- data => {
87
- f.write(data);
88
- });
89
- f.end();
90
- this.log.info('Compressing');
91
- const zipOutputName = `pg-backup-${this.now()}.zip`;
92
- await this.zip.zipDir(outputDir, outputDir.resolve(zipOutputName));
93
- this.fs.rmFile(dumpOut);
83
+ const zipOutPath = outputDir.resolve(`pg-backup-${this.now()}.sql.gz`);
84
+ this.log.info(`Dumping database to ${zipOutPath.str()}`);
85
+ await this.sh.exec(`docker run --rm --network host ` + `postgres:${version} ` + `bash -c '${bashCmds.join(' && ')}' | gzip> ${zipOutPath.str()}`);
94
86
  this.log.info('Uploading');
95
87
  storage.store(_Path.AbsPath.from(dir));
96
88
  });
@@ -112,16 +104,13 @@ let PgBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.m
112
104
  // TODO add e2e test for docker
113
105
 
114
106
  const zipFile = this.fs.listFiles(dir)[0];
115
- await this.zip.unzipDir(zipFile, dir);
116
- this.fs.rmFile(zipFile);
117
- const outFile = this.fs.listFiles(dir)[0];
118
- this.log.debug('Will run psql import from %s', outFile.str()); // Database is set to 'postgres' so that also users which don't have db created can use db-less URL
107
+ this.log.debug('Will run psql import from %s', zipFile.str()); // Database is set to 'postgres' so that also users which don't have db created can use db-less URL
119
108
  // Restoring user needs to have the admin access anyway
120
109
 
121
110
  const connectionArgs = `-h ${con.host} -p ${con.port} -U ${con.username} -d postgres`; // Don't forget that this itself might be run in docker
122
111
  // therefore volume mounts are not usable (will apply to the location at host)
123
112
 
124
- this.sh.exec(`docker run --network host -i ` + `-e PGPASSWORD=${con.password} ` + `postgres:${version} ` + `psql ${connectionArgs} -v ON_ERROR_STOP=0 < ${outFile.str()}`);
113
+ this.sh.exec(`gzip --decompress --stdout ${zipFile.str()} | docker run --network host -i ` + `-e PGPASSWORD=${con.password} ` + `postgres:${version} ` + `psql ${connectionArgs} -v ON_ERROR_STOP=0`);
125
114
  });
126
115
  });
127
116
  }
@@ -19,31 +19,46 @@ var _path = _interopRequireDefault(require("path"));
19
19
 
20
20
  var _promises = _interopRequireDefault(require("stream/promises"));
21
21
 
22
- var _dec, _class;
22
+ var _Shell = require("../shell/Shell");
23
+
24
+ var _dec, _dec2, _dec3, _class;
23
25
 
24
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
27
 
26
28
  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; }
27
29
 
28
- let Zipper = (_dec = (0, _inversify.injectable)(), _dec(_class = class Zipper {
29
- constructor() {
30
+ let Zipper = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.metadata("design:type", Function), _dec3 = Reflect.metadata("design:paramtypes", [typeof _Shell.Shell === "undefined" ? Object : _Shell.Shell]), _dec(_class = _dec2(_class = _dec3(_class = class Zipper {
31
+ constructor(sh) {
32
+ this.sh = sh;
33
+
30
34
  _defineProperty(this, "log", (0, _logging.classObjLog)(this));
31
35
 
32
36
  _defineProperty(this, "zipDir", async (dirPath, to) => {
33
- const srcDir = dirPath.str();
37
+ const src = dirPath.str();
34
38
  const dst = to.str();
35
39
 
36
40
  const dstDir = _path.default.dirname(dst);
37
41
 
38
- this.log.trace(`Zipping %s to %s`, srcDir, dst);
39
- const zip = new _jszip.default();
40
- buildZipFromDirectory(srcDir, zip);
41
- const r = await zip.generateNodeStream();
42
+ this.log.trace(`Zipping %s to %s`, src, dst);
42
43
 
43
44
  if (!_nodeFs.default.existsSync(dstDir)) {
44
45
  _nodeFs.default.mkdirSync(dstDir);
45
46
  }
46
47
 
48
+ await this.doDirZipInShell(src, dst);
49
+ });
50
+
51
+ _defineProperty(this, "doDirZipInShell", async (src, dst) => {
52
+ await this.sh.exec(`zip ${dst} -r .`, {
53
+ cwd: src
54
+ });
55
+ });
56
+
57
+ _defineProperty(this, "doDirZipInNodeJs", async (src, dst) => {
58
+ const zip = new _jszip.default();
59
+ buildZipFromDirectory(src, zip);
60
+ const r = await zip.generateNodeStream();
61
+
47
62
  const ws = _nodeFs.default.createWriteStream(dst);
48
63
 
49
64
  await _promises.default.pipeline(r, ws);
@@ -68,7 +83,7 @@ let Zipper = (_dec = (0, _inversify.injectable)(), _dec(_class = class Zipper {
68
83
  });
69
84
  }
70
85
 
71
- }) || _class);
86
+ }) || _class) || _class) || _class);
72
87
  exports.Zipper = Zipper;
73
88
 
74
89
  const buildZipFromDirectory = (dir, zip, root = dir) => {
@@ -8,12 +8,15 @@ var _testHelper = require("../../../test/testHelper");
8
8
 
9
9
  var _test = require("../../../test");
10
10
 
11
+ var _Shell = require("../shell/Shell");
12
+
11
13
  describe('zip', () => {
12
14
  afterEach(() => {
13
15
  (0, _testHelper.cleanTestDataDir)();
14
16
  });
15
17
  it('zip and unzip', async () => {
16
- const z = new _Zipper.Zipper();
18
+ const sh = new _Shell.Shell();
19
+ const z = new _Zipper.Zipper(sh);
17
20
  const out = (0, _test.testdataDirPath)('out.zip');
18
21
 
19
22
  const dir = _Path.AbsPath.from(__dirname).resolve('../../../test/foo');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ps-aux/nodebup",
3
- "version": "0.9.9",
3
+ "version": "0.10.0",
4
4
  "description": "",
5
5
  "module": "lib/index.js",
6
6
  "main": "lib/index.js",