@ps-aux/nodebup 0.9.10 → 0.11.1

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
  }
package/lib/cli/app.js CHANGED
@@ -53,55 +53,63 @@ const restoreOptions = [backupTagOption, {
53
53
  convertCase: true
54
54
  }];
55
55
 
56
- const createApp = () => _nclif.CliApp.of({
57
- commands: {
58
- dir: (0, _nclif.cmdGroup)({
59
- options: singleStorageOptions,
60
- commands: {
61
- backup: (0, _nclif.cmd)({
62
- description: 'Backup a dir to the given storage',
63
- options: backupOptions,
64
- positionals: [{
65
- name: 'path',
66
- required: true
67
- }],
68
- run: (cmd, c) => c.get(_DirBackupController.DirBackupController).backup(cmd)
69
- }),
70
- restore: (0, _nclif.cmd)({
71
- description: 'Restore the storage to the given dir',
72
- options: restoreOptions,
73
- positionals: [{
74
- name: 'path',
75
- required: true
76
- }],
77
- run: (cmd, c) => c.get(_DirBackupController.DirBackupController).restore(cmd)
78
- })
79
- }
80
- }),
81
- aggr: (0, _nclif.cmdGroup)({
82
- commands: {
83
- backup: (0, _nclif.cmd)({
84
- description: 'Run backup',
85
- options: [storageNameOpt],
86
- positionals: [{
87
- name: 'aggregateName',
88
- required: true
89
- }],
90
- run: (a, c) => c.get(_AggregateBackupController.AggregateBackupController).backup(a.aggregateName)
91
- })
92
- }
93
- }),
94
- restic,
95
- pg
96
- }
97
- }).envConfig('NODEBUP').addObjectConfig(pwd => (0, _Config.readConfig)(pwd)).context(({
98
- config,
99
- inputs
100
- }) => (0, _Context.createContext)(config, inputs));
56
+ const createApp = () => {
57
+ const p = _nclif.CliApp.of({
58
+ binName: 'bup',
59
+ description: 'Data backup utility'
60
+ }, {
61
+ commands: {
62
+ dir: (0, _nclif.cmdGroup)({
63
+ options: singleStorageOptions,
64
+ commands: {
65
+ backup: (0, _nclif.cmd)({
66
+ description: 'Backup a dir to the given storage',
67
+ options: backupOptions,
68
+ positionals: [{
69
+ name: 'path',
70
+ required: true
71
+ }],
72
+ run: (cmd, c) => c.get(_DirBackupController.DirBackupController).backup(cmd)
73
+ }),
74
+ restore: (0, _nclif.cmd)({
75
+ description: 'Restore the storage to the given dir',
76
+ options: restoreOptions,
77
+ positionals: [{
78
+ name: 'path',
79
+ required: true
80
+ }],
81
+ run: (cmd, c) => c.get(_DirBackupController.DirBackupController).restore(cmd)
82
+ })
83
+ }
84
+ }),
85
+ aggr: (0, _nclif.cmdGroup)({
86
+ commands: {
87
+ backup: (0, _nclif.cmd)({
88
+ description: 'Run backup',
89
+ options: [storageNameOpt],
90
+ positionals: [{
91
+ name: 'aggregateName',
92
+ required: true
93
+ }],
94
+ run: (a, c) => c.get(_AggregateBackupController.AggregateBackupController).backup(a.aggregateName)
95
+ })
96
+ }
97
+ }),
98
+ restic,
99
+ pg
100
+ }
101
+ }).envConfig('NODEBUP').addObjectConfig(pwd => (0, _Config.readConfig)(pwd)).context(({
102
+ config,
103
+ inputs
104
+ }) => (0, _Context.createContext)(config, inputs));
105
+
106
+ return p;
107
+ };
101
108
 
102
109
  exports.createApp = createApp;
103
110
  const restic = (0, _nclif.cmdGroup)({
104
111
  options: singleStorageOptions,
112
+ description: 'Restic commands',
105
113
  commands: {
106
114
  'init-repo': (0, _nclif.cmd)({
107
115
  run: (_, c) => c.get(_ResticController.ResticController).initRepo()
@@ -121,6 +129,7 @@ const restic = (0, _nclif.cmdGroup)({
121
129
  }
122
130
  });
123
131
  const pg = (0, _nclif.cmdGroup)({
132
+ description: 'Postgres backup commands',
124
133
  options: [...singleStorageOptions, {
125
134
  name: 'pg-url',
126
135
  convertCase: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ps-aux/nodebup",
3
- "version": "0.9.10",
3
+ "version": "0.11.1",
4
4
  "description": "",
5
5
  "module": "lib/index.js",
6
6
  "main": "lib/index.js",
@@ -78,7 +78,7 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "@hapi/joi": "^17.1.1",
81
- "@ps-aux/nclif": "^0.0.7-alpha.1",
81
+ "@ps-aux/nclif": "^0.9.0-alpha5",
82
82
  "@types/hapi__joi": "^17.1.8",
83
83
  "axios": "^0.24.0",
84
84
  "handlebars": "^4.7.7",