Log "backup restored" to watchdog after restore finished

Created on 22 August 2022, over 2 years ago
Updated 7 October 2023, about 1 year ago

Problem/Motivation

When we currently restore the default Drupal database, a status message appears noticing the user about the successful restoration of the database.

This notification will not show up under the watchdog page ("/admin/reports/dblog"), since the restoration message will be logged first, but reset afterwards by the restoration process

Steps to reproduce

  1. Restore the default drupal database via uploaded backup file
  2. See the status message "Restore complete ..." on page after restoration
  3. Check if the status message is shown under "recent log messages in "/admin/reports/dblog"
  4. The status message is not there

Proposed resolution

Log the restoration message after the watchdog reports get reset.

The log entry should include information about:

  • What was restored (backup name)
  • Status of restore (success, ...)
  • When it was restored
  • Who restored

Additionally, we could discuss if a "Description / note" would also make sense on restore like on backup creation. This could also simply be logged with the watchdog entry!

Feature request
Status

Needs review

Version

5.1

Component

Code

Created by

🇩🇪Germany Grevil

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • @tamerzg opened merge request.
  • Status changed to Needs review almost 2 years ago
  • 🇭🇷Croatia tamerzg

    Added status message to Drupal log:

    Restore completed using {backup_name} from {backup_location} into {destination} at {time}.

  • Issue was unassigned.
  • Status changed to Needs work almost 2 years ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @tamerzg - I added two comments. LGTM at all. Could you explain your choices?

  • 🇭🇷Croatia tamerzg

    @Anybody thanks for the review. I replied inside PR.

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks, moving both into the t() is just what I expected. Perfect! :)

  • Assigned to tamerzg
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • 🇭🇷Croatia tamerzg

    @Anybody I just updated PR, now $message string is built dynamically so we don't mix it with context variable. Please note that $message is not wrapped in t() as it shouldn't be, log messages are translated on display, but they are always stored in english/system language.

  • 🇩🇪Germany Anybody Porta Westfalica

    I personally don't really like this cluttered text approach, but other maintainers may see it different. Let's wait for further feedback.

  • 🇩🇪Germany Grevil

    OK, I think this needs further work.

    I agree with @Anybody. Not really a fan of the concatenated string approach. Furthermore, the log message text doesn't display the correct parameters.
    For the test, I made a backup of my site using the backup_migrate module and saved the backup in my private files directory. Afterwards I used the "Restore" option.

    This is my file dir / name : files/private/backup_migrate/backup-2023-02-13T10-35-05.mysql.gz

    And this is the log message result:

    Restore completed using backup_migrate_restore_upload from Upload into Default Drupal Database at Monday, February 13, 2023 - 10:37

  • Status changed to Needs work almost 2 years ago
  • 🇩🇪Germany Grevil

    Not really the expected outcome, but fairly close! :)

  • 🇩🇪Germany Grevil

    Update: The incorrect message only appears when restoring a backup using the "BackupMigrateRestoreForm" ("/admin/config/development/backup_migrate/restore" => the one with the file upload field). But the message appears correct, when restoring through the "BackupRestoreForm" ("/admin/config/development/backup_migrate/backups").

    The reason behind this is, that inside "BackupMigrateRestoreForm", "backup_migrate_perform_restore()" is called with hardcoded parameters for correct file usage of the file uploaded in the file upload field.

    Since this is working flawless for the "BackupRestoreForm":

    Restore completed using backup-2023-02-13T10-35-05.mysql.gz from Private Files Directory into Default Drupal Database at Monday, February 13, 2023 - 11:01.

    And we can not easily get file and destination IDs through the "BackupMigrateRestoreForm" without heavy refactoring, I suggest, we either display a static log message, keep it as is or remove the logging if the restoration was performed through the "BackupMigrateRestoreForm".

    Any other ideas or an easy fix for this problem are also welcome! :)

  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India nikhil_110

    The above MR is applied successfully for Backup and Migrate v5.1.x-dev.
    Attaching the screenshot for reference.

    Review Step

    • Setup Drupal 10.x with Backup and Migrate Module - 5.1.x-dev
    • Apply MR
    • Go to Administration > Configuration > Development > Backup and Migrate > Restore (Tab) > Restore now
    • After Go to Administration > Reports > Recent log messages > Backup and Migrate > Check backup_migrate Type log.


    The Backup is still not added in the log message as was suggested by @Anybody in #2.
    Review it too and let know if that is required.

  • 🇨🇦Canada xmacinfo Canada

    Using Backup and Migrate to restore a file (related to issue https://www.drupal.org/project/backup_migrate/issues/3264580 🐛 MySQL collation complexities leads to backup incompatibilities Active ), I expected to see a confirmation message.

    I did not see any message on the screen.

    In searching for another confirmation I looked at the watchdog and I did not see any entry related to restore or any Backup and Migrate entries.

    The only way I was able to confirm that the Backup and Migrated did the restore successfully was to look at the content and check for recent changes.

  • 🇨🇦Canada danrod Ottawa

    Tested this MR for 5.1.x and I can see the confirmation message after I restored an old backup, can be moved to RTBC.

Production build 0.71.5 2024