@ps-aux/nodebup 0.9.10 → 0.10.0
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.
@@ -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
|
}
|