Feat: Adding backup button for easy access to download a full server backup

This commit is contained in:
MCHost
2025-06-19 02:36:03 -04:00
parent d2498c0cf8
commit 16d8b52a01
4 changed files with 87 additions and 14 deletions

View File

@ -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}` };
}
}