Refactor backup and restore utilities for improved container handling

- Removed the `getRemoteServiceContainer` function and updated the `getServiceContainer` function to handle both local and remote service containers more efficiently.
- Refactored backup and restore commands for MariaDB, MongoDB, MySQL, and PostgreSQL to utilize new utility functions for generating backup and restore commands, enhancing code clarity and maintainability.
- Streamlined command execution logic in backup and restore processes, ensuring consistent handling of container IDs across different database types.
This commit is contained in:
Mauricio Siu
2025-05-03 13:24:05 -06:00
parent 0690f07262
commit 89306a7619
9 changed files with 115 additions and 142 deletions

View File

@@ -494,32 +494,9 @@ export const getCreateFileCommand = (
`;
};
export const getServiceContainer = async (appName: string) => {
try {
const filter = {
status: ["running"],
label: [`com.docker.swarm.service.name=${appName}`],
};
const containers = await docker.listContainers({
filters: JSON.stringify(filter),
});
if (containers.length === 0 || !containers[0]) {
throw new Error(`No container found with name: ${appName}`);
}
const container = containers[0];
return container;
} catch (error) {
throw error;
}
};
export const getRemoteServiceContainer = async (
serverId: string,
export const getServiceContainer = async (
appName: string,
serverId?: string | null,
) => {
try {
const filter = {