@ps-aux/nodebup 0.9.10 → 0.11.1
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 +6 -17
- package/lib/cli/app.js +54 -45
- package/package.json +2 -2
@@ -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('
|
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
|
84
|
-
|
85
|
-
await this.sh.
|
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
|
-
|
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
|
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 = () =>
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
})
|
98
|
-
|
99
|
-
|
100
|
-
}
|
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.
|
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
|
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",
|