backups... backups everywhere

This commit is contained in:
Andras Bacsai
2022-12-02 14:34:06 +01:00
parent 8a00b711be
commit f12d453b5f
12 changed files with 1433 additions and 11 deletions

View File

@@ -467,7 +467,6 @@ async function plausibleAnalytics(service: any, template: any) {
// Disconnect old service data
// await prisma.service.update({ where: { id: service.id }, data: { plausibleAnalytics: { disconnect: true } } })
}
async function migrateSettings(settings: any[], service: any, template: any) {
for (const setting of settings) {
try {
@@ -528,4 +527,4 @@ async function createVolumes(service: any, template: any) {
// console.log('Creating volume', volumeName, path, containerId, 'for service', service.id, ', service name:', service.name)
await prisma.servicePersistentStorage.findFirst({ where: { volumeName, serviceId: service.id } }) || await prisma.servicePersistentStorage.create({ data: { volumeName, path, containerId, predefined: true, service: { connect: { id: service.id } } } })
}
}
}

View File

@@ -14,6 +14,7 @@ import {
uniqueName,
version,
sentryDSN,
executeDockerCmd,
} from "../../../lib/common";
import { scheduler } from "../../../lib/scheduler";
import type { FastifyReply, FastifyRequest } from "fastify";
@@ -25,6 +26,35 @@ export async function hashPassword(password: string): Promise<string> {
return bcrypt.hash(password, saltRounds);
}
export async function backup(request: FastifyRequest) {
try {
const { backupData } = request.params;
let std = null;
const [id, backupType, type, zipped, storage] = backupData.split(':')
console.log(id, backupType, type, zipped, storage)
const database = await prisma.database.findUnique({ where: { id } })
if (database) {
// await executeDockerCmd({
// dockerId: database.destinationDockerId,
// command: `docker pull coollabsio/backup:latest`,
// })
std = await executeDockerCmd({
dockerId: database.destinationDockerId,
command: `docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v coolify-local-backup:/app/backups -e CONTAINERS_TO_BACKUP="${backupData}" coollabsio/backup`
})
}
if (std.stdout) {
return std.stdout;
}
if (std.stderr) {
return std.stderr;
}
return 'nope';
} catch ({ status, message }) {
return errorHandler({ status, message });
}
}
export async function cleanupManually(request: FastifyRequest) {
try {
const { serverId } = request.body;

View File

@@ -1,5 +1,5 @@
import { FastifyPluginAsync } from 'fastify';
import { checkUpdate, login, showDashboard, update, resetQueue, getCurrentUser, cleanupManually, restartCoolify } from './handlers';
import { checkUpdate, login, showDashboard, update, resetQueue, getCurrentUser, cleanupManually, restartCoolify, backup } from './handlers';
import { GetCurrentUser } from './types';
export interface Update {
@@ -52,6 +52,10 @@ const root: FastifyPluginAsync = async (fastify): Promise<void> => {
fastify.post('/internal/cleanup', {
onRequest: [fastify.authenticate]
}, async (request) => await cleanupManually(request));
fastify.get('/internal/backup/:backupData', {
onRequest: [fastify.authenticate]
}, async (request) => await backup(request));
};
export default root;