@@ -234,7 +234,7 @@ class SystemBackupService {
234234 if ( ! pool ) throw new Error ( 'PostgreSQL pool not initialized' ) ;
235235 await pool . query (
236236 `INSERT INTO system_backup_history
237- (dirname , timestamp, type, size, table_count, meshmonitor_version, schema_version , "createdAt")
237+ ("backupPath" , timestamp, "backupType", "totalSize", "tableCount", "appVersion", "schemaVersion" , "createdAt")
238238 VALUES ($1, $2, $3, $4, $5, $6, $7, $8)` ,
239239 [ dirname , timestamp , type , size , tableCount , meshmonitorVersion , schemaVersion , Date . now ( ) ]
240240 ) ;
@@ -243,15 +243,15 @@ class SystemBackupService {
243243 if ( ! pool ) throw new Error ( 'MySQL pool not initialized' ) ;
244244 await pool . execute (
245245 `INSERT INTO system_backup_history
246- (dirname , timestamp, type, size, table_count, meshmonitor_version, schema_version , createdAt)
246+ (backupPath , timestamp, backupType, totalSize, tableCount, appVersion, schemaVersion , createdAt)
247247 VALUES (?, ?, ?, ?, ?, ?, ?, ?)` ,
248248 [ dirname , timestamp , type , size , tableCount , meshmonitorVersion , schemaVersion , Date . now ( ) ]
249249 ) ;
250250 } else {
251251 const db = databaseService . db ;
252252 const stmt = db . prepare ( `
253253 INSERT INTO system_backup_history
254- (dirname , timestamp, type, size, table_count, meshmonitor_version, schema_version , createdAt)
254+ (backupPath , timestamp, backupType, totalSize, tableCount, appVersion, schemaVersion , createdAt)
255255 VALUES (?, ?, ?, ?, ?, ?, ?, ?)
256256 ` ) ;
257257 stmt . run ( dirname , timestamp , type , size , tableCount , meshmonitorVersion , schemaVersion , Date . now ( ) ) ;
@@ -468,10 +468,11 @@ class SystemBackupService {
468468 const backupPath = path . join ( SYSTEM_BACKUP_DIR , dirname ) ;
469469
470470 // Check if backup exists either in database or on disk
471+ const bpCol = dbType === 'postgres' ? '"backupPath"' : 'backupPath' ;
471472 const row = await this . queryOne (
472473 dbType === 'postgres'
473- ? ' SELECT dirname FROM system_backup_history WHERE dirname = $1'
474- : ' SELECT dirname FROM system_backup_history WHERE dirname = ?' ,
474+ ? ` SELECT ${ bpCol } FROM system_backup_history WHERE ${ bpCol } = $1`
475+ : ` SELECT ${ bpCol } FROM system_backup_history WHERE ${ bpCol } = ?` ,
475476 [ dirname ]
476477 ) ;
477478
@@ -490,8 +491,8 @@ class SystemBackupService {
490491 if ( row ) {
491492 await this . executeStatement (
492493 dbType === 'postgres'
493- ? ' DELETE FROM system_backup_history WHERE dirname = $1'
494- : ' DELETE FROM system_backup_history WHERE dirname = ?' ,
494+ ? ` DELETE FROM system_backup_history WHERE ${ bpCol } = $1`
495+ : ` DELETE FROM system_backup_history WHERE ${ bpCol } = ?` ,
495496 [ dirname ]
496497 ) ;
497498 }
@@ -531,31 +532,32 @@ class SystemBackupService {
531532
532533 // Get oldest backups to delete
533534 const toDelete = totalBackups - limit ;
535+ const bpCol = dbType === 'postgres' ? '"backupPath"' : 'backupPath' ;
534536 const oldBackups = await this . queryRows (
535537 dbType === 'postgres'
536- ? ' SELECT dirname FROM system_backup_history ORDER BY timestamp ASC LIMIT $1'
537- : ' SELECT dirname FROM system_backup_history ORDER BY timestamp ASC LIMIT ?' ,
538+ ? ` SELECT ${ bpCol } FROM system_backup_history ORDER BY timestamp ASC LIMIT $1`
539+ : ` SELECT ${ bpCol } FROM system_backup_history ORDER BY timestamp ASC LIMIT ?` ,
538540 [ toDelete ]
539541 ) ;
540542
541543 logger . info ( `🧹 Purging ${ oldBackups . length } old system backups (max: ${ limit } )...` ) ;
542544
543545 for ( const backup of oldBackups ) {
544546 // Delete directory from disk
545- const backupPath = path . join ( SYSTEM_BACKUP_DIR , backup . dirname ) ;
547+ const backupPath = path . join ( SYSTEM_BACKUP_DIR , backup . backupPath ) ;
546548 if ( fs . existsSync ( backupPath ) ) {
547549 fs . rmSync ( backupPath , { recursive : true , force : true } ) ;
548550 }
549551
550552 // Delete from database
551553 await this . executeStatement (
552554 dbType === 'postgres'
553- ? ' DELETE FROM system_backup_history WHERE dirname = $1'
554- : ' DELETE FROM system_backup_history WHERE dirname = ?' ,
555- [ backup . dirname ]
555+ ? ` DELETE FROM system_backup_history WHERE ${ bpCol } = $1`
556+ : ` DELETE FROM system_backup_history WHERE ${ bpCol } = ?` ,
557+ [ backup . backupPath ]
556558 ) ;
557559
558- logger . debug ( ` 🗑️ Purged: ${ backup . dirname } ` ) ;
560+ logger . debug ( ` 🗑️ Purged: ${ backup . backupPath } ` ) ;
559561 }
560562
561563 logger . info ( `✅ Purged ${ oldBackups . length } old system backups` ) ;
0 commit comments