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}` };
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user