@@ -545,52 +545,42 @@ export const backupRouter = createTRPCRouter({
545545 }
546546 const destination = await findDestinationById ( input . destinationId ) ;
547547 const queue : string [ ] = [ ] ;
548- const done = false ;
549- if ( input . backupType === "database" ) {
550- if ( input . databaseType === "postgres" ) {
551- const postgres = await findPostgresById ( input . databaseId ) ;
552-
553- restorePostgresBackup ( postgres , destination , input , ( log ) => {
554- queue . push ( log ) ;
555- } ) ;
556- }
557-
558- if ( input . databaseType === "mysql" ) {
559- const mysql = await findMySqlById ( input . databaseId ) ;
560- restoreMySqlBackup ( mysql , destination , input , ( log ) => {
561- queue . push ( log ) ;
562- } ) ;
563- }
564- if ( input . databaseType === "mariadb" ) {
565- const mariadb = await findMariadbById ( input . databaseId ) ;
566- restoreMariadbBackup ( mariadb , destination , input , ( log ) => {
567- queue . push ( log ) ;
568- } ) ;
569- }
570- if ( input . databaseType === "mongo" ) {
571- const mongo = await findMongoById ( input . databaseId ) ;
572- restoreMongoBackup ( mongo , destination , input , ( log ) => {
573- queue . push ( log ) ;
574- } ) ;
575- }
576- if ( input . databaseType === "libsql" ) {
577- const libsql = await findLibsqlById ( input . databaseId ) ;
578- restoreLibsqlBackup ( libsql , destination , input , ( log ) => {
579- queue . push ( log ) ;
580- } ) ;
581- }
582- if ( input . databaseType === "web-server" ) {
583- restoreWebServerBackup ( destination , input . backupFile , ( log ) => {
584- queue . push ( log ) ;
585- } ) ;
548+ let done = false ;
549+ const onLog = ( log : string ) => queue . push ( log ) ;
550+ const runRestore = async ( ) => {
551+ if ( input . backupType === "database" ) {
552+ if ( input . databaseType === "postgres" ) {
553+ const postgres = await findPostgresById ( input . databaseId ) ;
554+ await restorePostgresBackup ( postgres , destination , input , onLog ) ;
555+ } else if ( input . databaseType === "mysql" ) {
556+ const mysql = await findMySqlById ( input . databaseId ) ;
557+ await restoreMySqlBackup ( mysql , destination , input , onLog ) ;
558+ } else if ( input . databaseType === "mariadb" ) {
559+ const mariadb = await findMariadbById ( input . databaseId ) ;
560+ await restoreMariadbBackup ( mariadb , destination , input , onLog ) ;
561+ } else if ( input . databaseType === "mongo" ) {
562+ const mongo = await findMongoById ( input . databaseId ) ;
563+ await restoreMongoBackup ( mongo , destination , input , onLog ) ;
564+ } else if ( input . databaseType === "libsql" ) {
565+ const libsql = await findLibsqlById ( input . databaseId ) ;
566+ await restoreLibsqlBackup ( libsql , destination , input , onLog ) ;
567+ } else if ( input . databaseType === "web-server" ) {
568+ await restoreWebServerBackup ( destination , input . backupFile , onLog ) ;
569+ }
570+ } else if ( input . backupType === "compose" ) {
571+ const compose = await findComposeById ( input . databaseId ) ;
572+ await restoreComposeBackup ( compose , destination , input , onLog ) ;
586573 }
587- }
588- if ( input . backupType === "compose" ) {
589- const compose = await findComposeById ( input . databaseId ) ;
590- restoreComposeBackup ( compose , destination , input , ( log ) => {
591- queue . push ( log ) ;
574+ } ;
575+ runRestore ( )
576+ . catch ( ( error ) => {
577+ onLog (
578+ `Error: ${ error instanceof Error ? error . message : String ( error ) } ` ,
579+ ) ;
580+ } )
581+ . finally ( ( ) => {
582+ done = true ;
592583 } ) ;
593- }
594584 while ( ! done || queue . length > 0 ) {
595585 if ( queue . length > 0 ) {
596586 yield queue . shift ( ) ! ;
0 commit comments