update backups

This commit is contained in:
Andras Bacsai
2023-07-25 12:33:05 +02:00
parent 49261308f7
commit 343957ab8b
3 changed files with 6 additions and 12 deletions

View File

@@ -1943,11 +1943,11 @@ export function generateSecrets(
return envs; return envs;
} }
export async function backupPostgresqlDatabase(database, reply) { export async function backupDatabaseNow(database, reply) {
const backupFolder = '/tmp' const backupFolder = '/tmp'
const fileName = `${database.id}-${new Date().getTime()}.gz` const fileName = `${database.id}-${new Date().getTime()}.gz`
const backupFileName = `${backupFolder}/${fileName}` const backupFileName = `${backupFolder}/${fileName}`
console.log({ database }) const backupStorageFilename = `/app/backups/${fileName}`
let command = null let command = null
switch (database?.type) { switch (database?.type) {
case 'postgresql': case 'postgresql':
@@ -1972,17 +1972,11 @@ export async function backupPostgresqlDatabase(database, reply) {
dockerId: database.destinationDockerId, dockerId: database.destinationDockerId,
command, command,
}); });
const copyCommand = `docker cp ${database.id}:${backupFileName} ${backupFileName}` const copyCommand = `docker cp ${database.id}:${backupFileName} ${backupStorageFilename}`
await executeCommand({ await executeCommand({
dockerId: database.destinationDockerId, dockerId: database.destinationDockerId,
command: copyCommand command: copyCommand
}); });
if (isDev) {
await executeCommand({
dockerId: database.destinationDockerId,
command: `docker cp ${database.id}:${backupFileName} /app/backups/`
});
}
const stream = fsNormal.createReadStream(backupFileName); const stream = fsNormal.createReadStream(backupFileName);
reply.header('Content-Type', 'application/octet-stream'); reply.header('Content-Type', 'application/octet-stream');
reply.header('Content-Disposition', `attachment; filename=${fileName}`); reply.header('Content-Disposition', `attachment; filename=${fileName}`);

View File

@@ -5,7 +5,7 @@ import yaml from 'js-yaml';
import fs from 'fs/promises'; import fs from 'fs/promises';
import { import {
ComposeFile, ComposeFile,
backupPostgresqlDatabase, backupDatabaseNow,
createDirectories, createDirectories,
decrypt, decrypt,
defaultComposeConfiguration, defaultComposeConfiguration,
@@ -362,7 +362,7 @@ export async function backupDatabase(request: FastifyRequest<OnlyId>, reply: Fas
}); });
if (database.dbUserPassword) database.dbUserPassword = decrypt(database.dbUserPassword); if (database.dbUserPassword) database.dbUserPassword = decrypt(database.dbUserPassword);
if (database.rootUserPassword) database.rootUserPassword = decrypt(database.rootUserPassword); if (database.rootUserPassword) database.rootUserPassword = decrypt(database.rootUserPassword);
return await backupPostgresqlDatabase(database, reply); return await backupDatabaseNow(database, reply);
} catch ({ status, message }) { } catch ({ status, message }) {
return errorHandler({ status, message }); return errorHandler({ status, message });
} }

View File

@@ -138,7 +138,7 @@
loading.backup = true; loading.backup = true;
addToast({ addToast({
message: message:
'Backup will be downloaded soon and saved to /var/lib/docker/volumes/coolify-local-backup/ on the host system.', 'Backup will be downloaded soon and saved to /var/lib/docker/volumes/coolify-local-backup/_data/ on the host system.',
type: 'success', type: 'success',
timeout: 15000 timeout: 15000
}); });