diff --git a/apps/dokploy/server/api/routers/backup.ts b/apps/dokploy/server/api/routers/backup.ts index 6d358f631..ead1ef4b6 100644 --- a/apps/dokploy/server/api/routers/backup.ts +++ b/apps/dokploy/server/api/routers/backup.ts @@ -545,52 +545,42 @@ export const backupRouter = createTRPCRouter({ } const destination = await findDestinationById(input.destinationId); const queue: string[] = []; - const done = false; - if (input.backupType === "database") { - if (input.databaseType === "postgres") { - const postgres = await findPostgresById(input.databaseId); - - restorePostgresBackup(postgres, destination, input, (log) => { - queue.push(log); - }); + let done = false; + const onLog = (log: string) => queue.push(log); + const runRestore = async () => { + if (input.backupType === "database") { + if (input.databaseType === "postgres") { + const postgres = await findPostgresById(input.databaseId); + await restorePostgresBackup(postgres, destination, input, onLog); + } else if (input.databaseType === "mysql") { + const mysql = await findMySqlById(input.databaseId); + await restoreMySqlBackup(mysql, destination, input, onLog); + } else if (input.databaseType === "mariadb") { + const mariadb = await findMariadbById(input.databaseId); + await restoreMariadbBackup(mariadb, destination, input, onLog); + } else if (input.databaseType === "mongo") { + const mongo = await findMongoById(input.databaseId); + await restoreMongoBackup(mongo, destination, input, onLog); + } else if (input.databaseType === "libsql") { + const libsql = await findLibsqlById(input.databaseId); + await restoreLibsqlBackup(libsql, destination, input, onLog); + } else if (input.databaseType === "web-server") { + await restoreWebServerBackup(destination, input.backupFile, onLog); + } + } else if (input.backupType === "compose") { + const compose = await findComposeById(input.databaseId); + await restoreComposeBackup(compose, destination, input, onLog); } - - if (input.databaseType === "mysql") { - const mysql = await findMySqlById(input.databaseId); - restoreMySqlBackup(mysql, destination, input, (log) => { - queue.push(log); - }); - } - if (input.databaseType === "mariadb") { - const mariadb = await findMariadbById(input.databaseId); - restoreMariadbBackup(mariadb, destination, input, (log) => { - queue.push(log); - }); - } - if (input.databaseType === "mongo") { - const mongo = await findMongoById(input.databaseId); - restoreMongoBackup(mongo, destination, input, (log) => { - queue.push(log); - }); - } - if (input.databaseType === "libsql") { - const libsql = await findLibsqlById(input.databaseId); - restoreLibsqlBackup(libsql, destination, input, (log) => { - queue.push(log); - }); - } - if (input.databaseType === "web-server") { - restoreWebServerBackup(destination, input.backupFile, (log) => { - queue.push(log); - }); - } - } - if (input.backupType === "compose") { - const compose = await findComposeById(input.databaseId); - restoreComposeBackup(compose, destination, input, (log) => { - queue.push(log); + }; + runRestore() + .catch((error) => { + onLog( + `Error: ${error instanceof Error ? error.message : String(error)}`, + ); + }) + .finally(() => { + done = true; }); - } while (!done || queue.length > 0) { if (queue.length > 0) { yield queue.shift()!; diff --git a/apps/dokploy/server/api/routers/libsql.ts b/apps/dokploy/server/api/routers/libsql.ts index 614e42101..79dcc4443 100644 --- a/apps/dokploy/server/api/routers/libsql.ts +++ b/apps/dokploy/server/api/routers/libsql.ts @@ -246,11 +246,15 @@ export const libsqlRouter = createTRPCRouter({ deployment: ["create"], }); const queue: string[] = []; - const done = false; + let done = false; deployLibsql(input.libsqlId, (log) => { queue.push(log); - }); + }) + .catch(() => {}) + .finally(() => { + done = true; + }); while (!done || queue.length > 0) { if (queue.length > 0) { diff --git a/apps/dokploy/server/api/routers/mongo.ts b/apps/dokploy/server/api/routers/mongo.ts index a64535e24..47c06f819 100644 --- a/apps/dokploy/server/api/routers/mongo.ts +++ b/apps/dokploy/server/api/routers/mongo.ts @@ -228,11 +228,15 @@ export const mongoRouter = createTRPCRouter({ deployment: ["create"], }); const queue: string[] = []; - const done = false; + let done = false; deployMongo(input.mongoId, (log) => { queue.push(log); - }); + }) + .catch(() => {}) + .finally(() => { + done = true; + }); while (!done || queue.length > 0) { if (queue.length > 0) { diff --git a/apps/dokploy/server/api/routers/mysql.ts b/apps/dokploy/server/api/routers/mysql.ts index abb0f97a7..8e1938caa 100644 --- a/apps/dokploy/server/api/routers/mysql.ts +++ b/apps/dokploy/server/api/routers/mysql.ts @@ -230,11 +230,15 @@ export const mysqlRouter = createTRPCRouter({ }); const queue: string[] = []; - const done = false; + let done = false; deployMySql(input.mysqlId, (log) => { queue.push(log); - }); + }) + .catch(() => {}) + .finally(() => { + done = true; + }); while (!done || queue.length > 0) { if (queue.length > 0) { diff --git a/apps/dokploy/server/api/routers/postgres.ts b/apps/dokploy/server/api/routers/postgres.ts index 3b3cfd208..b591726eb 100644 --- a/apps/dokploy/server/api/routers/postgres.ts +++ b/apps/dokploy/server/api/routers/postgres.ts @@ -233,11 +233,15 @@ export const postgresRouter = createTRPCRouter({ }); const queue: string[] = []; - const done = false; + let done = false; deployPostgres(input.postgresId, (log) => { queue.push(log); - }); + }) + .catch(() => {}) + .finally(() => { + done = true; + }); while (!done || queue.length > 0) { if (queue.length > 0) { diff --git a/apps/dokploy/server/api/routers/redis.ts b/apps/dokploy/server/api/routers/redis.ts index 01d922aa4..dfd8e1a87 100644 --- a/apps/dokploy/server/api/routers/redis.ts +++ b/apps/dokploy/server/api/routers/redis.ts @@ -251,11 +251,15 @@ export const redisRouter = createTRPCRouter({ deployment: ["create"], }); const queue: string[] = []; - const done = false; + let done = false; deployRedis(input.redisId, (log) => { queue.push(log); - }); + }) + .catch(() => {}) + .finally(() => { + done = true; + }); while (!done || queue.length > 0) { if (queue.length > 0) {