From 7678e02547fb34545b319cde19a36301b806e492 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 18 Nov 2026 18:45:32 +0530 Subject: [PATCH 1/2] fix(restore): mention the database after a rollback only when it was re-imported MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After a restore failed and was rolled back, the success line always said "…and the database was re-imported from the copy taken before it.", also when the restore had no database step (an html site, or a php site without a database) and the database was never touched. The two messages for a rollback that didn't complete pointed at db-before.sql in the same case, although there was no such copy. The rollback messages now mention the database only when the transaction shows its import had started, the only case in which the rollback re-imports it. The rollback itself is unchanged. --- src/helper/Site_Backup_Restore.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/helper/Site_Backup_Restore.php b/src/helper/Site_Backup_Restore.php index 2845fe78..8c8de0df 100644 --- a/src/helper/Site_Backup_Restore.php +++ b/src/helper/Site_Backup_Restore.php @@ -2162,7 +2162,7 @@ public function rollback_restore_on_shutdown() { $this->rollback_unfinished_restore(); } catch ( \Throwable $e ) { // An exception here would also skip the shutdown handlers registered after this one. - $where = null === $this->restore_txn ? '' : sprintf( ' The previous site files are in %1$s/old and the previous database in %1$s/db-before.sql; the next `ee site restore` retries the rollback.', $this->restore_txn['stage'] ); + $where = null === $this->restore_txn ? '' : sprintf( ' %s; the next `ee site restore` retries the rollback.', $this->describe_rollback_leftovers( $this->restore_txn ) ); EE::warning( 'The rollback stopped: ' . $e->getMessage() . $where ); } $this->in_shutdown = false; @@ -2187,15 +2187,29 @@ private function rollback_unfinished_restore() { return; } - $stage = $this->restore_txn['stage']; + $txn = $this->restore_txn; EE::warning( 'The restore did not complete. Rolling the site back.' ); if ( $this->rollback_restore_transaction() ) { - EE::log( 'Rolled back: the site files and configuration are as they were before the restore, and the database was re-imported from the copy taken before it.' ); + // The DB is put back only when the import had started; before that it was never changed. + EE::log( 'Rolled back: the site files and configuration are as they were before the restore' . ( 'importing' === $txn['db'] ? ', and the database was re-imported from the copy taken before it.' : '.' ) ); } else { - EE::warning( sprintf( 'The rollback did not complete. The previous site files are in %s/old and the previous database in %s/db-before.sql; the next `ee site restore` retries the rollback.', $stage, $stage ) ); + EE::warning( sprintf( 'The rollback did not complete. %s; the next `ee site restore` retries the rollback.', $this->describe_rollback_leftovers( $txn ) ) ); } } + /** + * @param array $txn Restore transaction. + * + * @return string Where an unfinished rollback left the previous site files, and the previous DB once its import had started. + */ + private function describe_rollback_leftovers( array $txn ) { + if ( 'importing' === $txn['db'] ) { + return sprintf( 'The previous site files are in %1$s/old and the previous database in %1$s/db-before.sql', $txn['stage'] ); + } + + return sprintf( 'The previous site files are in %s/old', $txn['stage'] ); + } + /** * Roll back a restore that was killed before it finished (its journal is left in EE_BACKUP_DIR). */ From d340657a4b0567d3222c9a3ec02639eee04d1f0f Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 19 Nov 2026 10:18:47 +0530 Subject: [PATCH 2/2] fix(backup): describe only the rollback leftovers that are on disk When a rollback does not complete, the warning always said the previous site files are in /old and, after the DB import had started, that the previous database is in /db-before.sql. Neither is guaranteed: a failure before the file swap leaves /old empty, and the dump can be missing. The warning now names /old only when files are still staged there, names db-before.sql only when it exists, says the copy of the previous database is missing otherwise, and says no previous site files are staged when there is nothing to point at. --- src/helper/Site_Backup_Restore.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/helper/Site_Backup_Restore.php b/src/helper/Site_Backup_Restore.php index 8c8de0df..28cc1997 100644 --- a/src/helper/Site_Backup_Restore.php +++ b/src/helper/Site_Backup_Restore.php @@ -2203,11 +2203,21 @@ private function rollback_unfinished_restore() { * @return string Where an unfinished rollback left the previous site files, and the previous DB once its import had started. */ private function describe_rollback_leftovers( array $txn ) { + // Describe what is on disk now: the swap may not have started, and the dump may be gone. + $parts = []; + if ( ! empty( $this->list_dir( $txn['stage'] . '/old' ) ) ) { + $parts[] = sprintf( 'The previous site files still staged are in %s/old', $txn['stage'] ); + } if ( 'importing' === $txn['db'] ) { - return sprintf( 'The previous site files are in %1$s/old and the previous database in %1$s/db-before.sql', $txn['stage'] ); + $parts[] = is_file( $txn['stage'] . '/db-before.sql' ) + ? sprintf( 'the previous database is in %s/db-before.sql', $txn['stage'] ) + : 'the copy of the previous database is missing'; + } + if ( empty( $parts ) ) { + return sprintf( 'No previous site files are staged in %s', $txn['stage'] ); } - return sprintf( 'The previous site files are in %s/old', $txn['stage'] ); + return ucfirst( implode( ' and ', $parts ) ); } /**