services: fix usage of pipework
This commit is contained in:
+17
-8
@@ -54,6 +54,7 @@ const addonConfigs = require('./addonconfigs.js'),
|
||||
eventlog = require('./eventlog.js'),
|
||||
fs = require('node:fs'),
|
||||
hat = require('./hat.js'),
|
||||
http = require('http'),
|
||||
infra = require('./infra_version.js'),
|
||||
logs = require('./logs.js'),
|
||||
mail = require('./mail.js'),
|
||||
@@ -1342,7 +1343,8 @@ async function backupMySql(app, options) {
|
||||
const result = await getContainerDetails('mysql', 'CLOUDRON_MYSQL_TOKEN');
|
||||
|
||||
const url = `http://${result.ip}:3000/` + (options.multipleDatabases ? 'prefixes' : 'databases') + `/${database}/backup?access_token=${result.token}`;
|
||||
const [error] = await safe(pipeRequestToFile(url, dumpPath('mysql', app.id)));
|
||||
const request = http.request(url, { method: 'POST' });
|
||||
const [error] = await safe(pipeRequestToFile(request, dumpPath('mysql', app.id)));
|
||||
if (error) throw new BoxError(BoxError.ADDONS_ERROR, `Error backing up MySQL: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -1357,7 +1359,8 @@ async function restoreMySql(app, options) {
|
||||
const result = await getContainerDetails('mysql', 'CLOUDRON_MYSQL_TOKEN');
|
||||
|
||||
const url = `http://${result.ip}:3000/` + (options.multipleDatabases ? 'prefixes' : 'databases') + `/${database}/restore?access_token=${result.token}`;
|
||||
const [error] = await safe(pipeFileToRequest(dumpPath('mysql', app.id), url));
|
||||
const request = http.request(url, { method: 'POST' });
|
||||
const [error] = await safe(pipeFileToRequest(dumpPath('mysql', app.id), request));
|
||||
if (error) throw new BoxError(BoxError.ADDONS_ERROR, `MySQL restore failed. This may require more memory. Check logs in the Services view. Details: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -1497,7 +1500,8 @@ async function backupPostgreSql(app, options) {
|
||||
const { database } = postgreSqlNames(app.id);
|
||||
|
||||
const result = await getContainerDetails('postgresql', 'CLOUDRON_POSTGRESQL_TOKEN');
|
||||
const [error] = await safe(pipeRequestToFile(`http://${result.ip}:3000/databases/${database}/backup?access_token=${result.token}`, dumpPath('postgresql', app.id)));
|
||||
const request = http.request(`http://${result.ip}:3000/databases/${database}/backup?access_token=${result.token}`, { method: 'POST' });
|
||||
const [error] = await safe(pipeRequestToFile(request, dumpPath('postgresql', app.id)));
|
||||
if (error) throw new BoxError(BoxError.ADDONS_ERROR, `Error backing up PostgreSQL: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -1511,7 +1515,8 @@ async function restorePostgreSql(app, options) {
|
||||
|
||||
const result = await getContainerDetails('postgresql', 'CLOUDRON_POSTGRESQL_TOKEN');
|
||||
|
||||
const [error] = await safe(pipeFileToRequest(dumpPath('postgresql', app.id), `http://${result.ip}:3000/databases/${database}/restore?access_token=${result.token}&username=${username}`));
|
||||
const request = http.request(`http://${result.ip}:3000/databases/${database}/restore?access_token=${result.token}&username=${username}`, { method: 'POST' });
|
||||
const [error] = await safe(pipeFileToRequest(dumpPath('postgresql', app.id), request));
|
||||
if (error) throw new BoxError(BoxError.ADDONS_ERROR, `PostgreSQL restore failed. This may require more memory. Check logs in the Services view. Details: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -1666,7 +1671,8 @@ async function backupMongoDb(app, options) {
|
||||
const database = await addonConfigs.getByName(app.id, 'mongodb', '%MONGODB_DATABASE');
|
||||
if (!database) throw new BoxError(BoxError.NOT_FOUND, 'Error backing up MongoDB. No database');
|
||||
|
||||
const [error] = await safe(pipeRequestToFile(`http://${result.ip}:3000/databases/${database}/backup?access_token=${result.token}`, dumpPath('mongodb', app.id)));
|
||||
const request = http.request(`http://${result.ip}:3000/databases/${database}/backup?access_token=${result.token}`, { method: 'POST' });
|
||||
const [error] = await safe(pipeRequestToFile(request, dumpPath('mongodb', app.id)));
|
||||
if (error) throw new BoxError(BoxError.ADDONS_ERROR, `Error backing up MongoDB: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -1683,7 +1689,8 @@ async function restoreMongoDb(app, options) {
|
||||
const database = await addonConfigs.getByName(app.id, 'mongodb', '%MONGODB_DATABASE');
|
||||
if (!database) throw new BoxError(BoxError.NOT_FOUND, 'Error restoring MongoDB. No database');
|
||||
|
||||
const [error] = await safe(pipeFileToRequest(dumpPath('mongodb', app.id), `http://${result.ip}:3000/databases/${database}/restore?access_token=${result.token}`));
|
||||
const request = http.request(`http://${result.ip}:3000/databases/${database}/restore?access_token=${result.token}`, { method: 'POST' });
|
||||
const [error] = await safe(pipeFileToRequest(dumpPath('mongodb', app.id), request));
|
||||
if (error) throw new BoxError(BoxError.ADDONS_ERROR, `MongoDB restore failed. This may require more memory. Check logs in the Services view. Details: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -1934,7 +1941,8 @@ async function backupRedis(app, options) {
|
||||
debug('Backing up redis');
|
||||
|
||||
const result = await getContainerDetails('redis-' + app.id, 'CLOUDRON_REDIS_TOKEN');
|
||||
const [error] = await safe(pipeRequestToFile(`http://${result.ip}:3000/backup?access_token=${result.token}`, dumpPath('redis', app.id)));
|
||||
const request = http.request(`http://${result.ip}:3000/backup?access_token=${result.token}`, { method: 'POST' });
|
||||
const [error] = await safe(pipeRequestToFile(request, dumpPath('redis', app.id)));
|
||||
if (error) throw new BoxError(BoxError.ADDONS_ERROR, `Error backing up Redis: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -1948,7 +1956,8 @@ async function restoreRedis(app, options) {
|
||||
debug('Restoring redis');
|
||||
|
||||
const result = await getContainerDetails('redis-' + app.id, 'CLOUDRON_REDIS_TOKEN');
|
||||
const [error] = await safe(pipeFileToRequest(dumpPath('redis', app.id), `http://${result.ip}:3000/restore?access_token=${result.token}`));
|
||||
const request = http.request(`http://${result.ip}:3000/restore?access_token=${result.token}`, { method: 'POST' });
|
||||
const [error] = await safe(pipeFileToRequest(dumpPath('redis', app.id), request));
|
||||
if (error) throw new BoxError(BoxError.ADDONS_ERROR, `Redis restore failed. This may require more memory. Check logs in the Services view. Details: ${error.message}`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user