Feat: Adding backup button for easy access to download a full server backup
This commit is contained in:
@ -200,4 +200,27 @@ export async function updateMods(docker, containerName) {
|
||||
} catch (error) {
|
||||
return { error: `Failed to update mods: ${error.message}` };
|
||||
}
|
||||
}
|
||||
|
||||
export async function createBackup(docker, containerName) {
|
||||
try {
|
||||
const container = docker.getContainer(containerName);
|
||||
const inspect = await container.inspect();
|
||||
if (inspect.State.Status !== 'running') {
|
||||
return { error: `Container ${containerName} is not running` };
|
||||
}
|
||||
const command = `docker exec -t ${containerName} bash -c "/home/backup.sh | grep export"`;
|
||||
const { stdout, stderr } = await execPromise(command);
|
||||
if (stderr) return { error: stderr };
|
||||
|
||||
// Extract the URL using a regular expression
|
||||
const urlRegex = /(https:\/\/[^\s]+)/;
|
||||
const match = stdout.match(urlRegex);
|
||||
if (!match) return { error: 'No download URL found in backup output' };
|
||||
|
||||
const downloadURL = match[0];
|
||||
return { output: 'Backup completed successfully', downloadURL };
|
||||
} catch (error) {
|
||||
return { error: `Failed to create backup: ${error.message}` };
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { URLSearchParams } from 'url';
|
||||
import { getContainerStats, streamContainerLogs, readServerProperties, writeServerProperties, updateMods } from './docker.js';
|
||||
import { getContainerStats, streamContainerLogs, readServerProperties, writeServerProperties, updateMods, createBackup } from './docker.js';
|
||||
import { checkConnectionStatus, checkGeyserStatus, checkSftpStatus } from './status.js';
|
||||
import { apiRequest } from './api.js';
|
||||
|
||||
@ -42,7 +42,6 @@ function startDockerStatsInterval(ws, client, user, docker) {
|
||||
const container = docker.getContainer(user);
|
||||
const inspect = await container.inspect();
|
||||
if (inspect.State.Status !== 'running') {
|
||||
// console.log(`Container ${user} not running, sending error`);
|
||||
ws.send(JSON.stringify({ type: 'docker', error: `Container ${user} is not running` }));
|
||||
return;
|
||||
}
|
||||
@ -247,7 +246,7 @@ async function manageStatusChecks(ws, client, user, docker) {
|
||||
if (data && data.hostname && data.port) {
|
||||
const status = await checkFn(data.hostname, data.port);
|
||||
if (ws.readyState === ws.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'connection-status', data: { isOnline: status.isOnline } }));
|
||||
ws.send(JSON.stringify({ type: statusType, data: { isOnline: status.isOnline } }));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@ -483,6 +482,8 @@ export function handleWebSocket(ws, req, docker) {
|
||||
response = client.user === 'Unknown' ? { error: 'User not identified' } : await writeServerProperties(docker, client.user, body.content);
|
||||
} else if (endpoint === '/update-mods' && method === 'POST') {
|
||||
response = client.user === 'Unknown' ? { error: 'User not identified' } : await updateMods(docker, client.user);
|
||||
} else if (endpoint === '/backup' && method === 'POST') {
|
||||
response = client.user === 'Unknown' ? { error: 'User not identified' } : await createBackup(docker, client.user);
|
||||
} else {
|
||||
response = await apiRequest(endpoint, client.apiKey, method, body);
|
||||
}
|
||||
|
Reference in New Issue
Block a user