Download errors, backup files contain trailing HTML, corrupts archive backups

Created on 16 August 2021, over 3 years ago
Updated 20 September 2024, 2 months ago

Problem/Motivation

I install the 5.0.1 version in Drupal 8.9.18 using ddev and cant download a database only get the error:

Failed network - error

I found this log message:

access denied
Path: /admin/config/development/backup_migrate/advanced. Drupal\Core\Http\Exception\CacheableAccessDeniedHttpException: The 'perform backup' permission is required. in Drupal\Core\Routing\AccessAwareRouter->checkAccess() (line 117 of /var/www/html/core/lib/Drupal/Core/Routing/AccessAwareRouter.php).

See also πŸ› Backup files contain trailing HTML, corrupts archive backups Closed: duplicate for more debugging progress prior to this issue and possible issue credits.

πŸ› Bug report
Status

RTBC

Version

5.1

Component

Code

Created by

πŸ‡²πŸ‡½Mexico koffer

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

Merge Requests

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.
  • Merge request !29Issue #3228379: Failed network - error β†’ (Merged) created by Grevil
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    8 pass, 2 fail
  • πŸ‡©πŸ‡ͺGermany Grevil

    I applied patch #19 by @jillh68 and created a simple test.

    Unfortunately, the test results in Drupal still being in maintenance mode, after the backup has finished. Manually testing this will result in the correct expected behaviour... Maybe the test is missing something, I am unsure.

  • Status changed to Needs review over 1 year ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    Setting this to "needs review", maybe someone can fix the test.

  • Status changed to Needs work over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    8 pass, 2 fail
  • Status changed to Needs review over 1 year ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    Tests were actually correct.

    The site will NOT leave maintenance mode, if the backup destination is set to "Download". But it WILL leave maintenance mode, if "Private Files Directory" is set as the backup destination.

    This is represented in the added test.

  • Adding related issue, since it was mentioned in #16 and #17 that downloaded files contain html.

  • Status changed to RTBC 11 months ago
  • After testing the MR, I can confirm that the applied changes fix the related issue with trailing HTML on downloaded backups!

    I will mark that issue a duplicate of this one. Thank you for the fix!

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 8.0 & MySQL 5.7
    last update 11 months ago
    8 pass, 2 fail
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update 11 months ago
    7 pass, 4 fail
  • Bumping priority to match that of the related issue.

  • Status changed to Needs work 11 months ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    Just found a bug, while fixing the last failing test. When downloading the backup, and simultaneously having "Take site offline" checked, the site won't go online after the download has finished.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 8.0 & MySQL 5.7
    last update 11 months ago
    8 pass, 2 fail
  • πŸ‡©πŸ‡ͺGermany Grevil

    Taking a further look, the destinations "download" (and "upload" for some reason) are added through line 144-149 in backup_migrate.module:

    // @todo Make this better.
    if (empty($options['nobrowser'])) {
    // Add a download destination.
    $user = \Drupal::currentUser();
    if ($user->hasPermission('access backup files')) {
    $destinations->add('download', new DrupalBrowserDownloadDestination(new Config(['name' => t('Download')])));
    }
    // Add an upload destination.
    $destinations->add('upload', new DrupalBrowserUploadDestination(new Config(['name' => t('Upload')])));
    }

    I think, that is the root of the problem. "private_files" is generated through an install .yml file ("backup_migrate.backup_migrate_destination.private_files.yml"). Although I don't completely understand the workflow yet. I first thought destinations would be simply plugins, but they are not.
    The PluginManager calls all plugins "teardown" method, if they implement one. With private files this is no problem, but instead of destinations being plugins and having their "teardown" function bring the drupal site out of maintenance mode, destination seems to be something else, and instead the "DrupalUtils" plugin will get the site back online, but it only does that for private_files, even though we add the DrupalUtils plugin a few lines below of the before mentioned destination additions.

    No idea, we could disallow taking the site offline for both download and upload destinations as a quick fix. Everything else needs to be done by someone with further knowledge.

  • Should a test also be added to ensure that the related issue doesn't occur again? (Making sure that the downloaded backup is correct)

  • @Grevil, I think it would be okay to disable taking the site offline for download, for sure, since you can easily download the file afterwards at /admin/config/development/backup_migrate/backups.

    I haven't used the upload destination, so I don't know for that one.

  • Pipeline finished with Failed
    2 months ago
    Total: 256s
    #280261
  • πŸ‡©πŸ‡ͺGermany Grevil

    Don't have the full picture, since I commented / added code here a while ago, but we could skip the test using the "take site offline" setting (testAdvancedBackupWithMaintenanceModeEnabledDestinationDownload), if that is manually tested and damien is fine with that.

    This is the last issue blocking the D11 compatible 5.1.x release.

    If you want to finish the test @solideogloria, the current problem is, that in testAdvancedBackupWithMaintenanceModeEnabledDestinationDownload in line 511, the site is still in maintenance mode ("Current response status code is 503, but 200 expected"), maybe a race condition? Unsure as I haven't touched this in a while, maybe you find a way to fix, (or we remove the test entirely, if that is ok).

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    @Grevil I'd say we should either revert that feature or finally fix the effects of this issue, to not block the 5.1.0 release. How to proceed?

  • Pipeline finished with Canceled
    2 months ago
    Total: 81s
    #286125
  • Pipeline finished with Success
    2 months ago
    Total: 206s
    #286126
  • Status changed to Needs review 2 months ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    Ok, we now throw a validation error, when the "site_offline" checkbox is checked AND the "destination_id" is set to "download". I also adjusted the tests accordingly.
    I created a minor follow-up issue, where we can resolve this incompatibility in the future: πŸ› Problem with "advanced backup" when checking destination "download" and "take site offline" Active .

    @Grevil, I think it would be okay to disable taking the site offline for download, for sure, since you can easily download the file afterwards at /admin/config/development/backup_migrate/backups.

    Not really a big fan of disabling the checkbox through drupal states. The "site_offline" checkbox comes before the "destination_id" select, so if the user checks the checkbox, and changes the destination he won't even see, that the checkbox is suddenly disabled and the validation error occurs. Then he has to scroll all the way down to use a different destination just so he can uncheck the checkbox again. Additionally to disabling the checkbox, we could uncheck it automatically, once the destination changes to "download" but this is even more risky IMO, as then the user might accidentally does NOT take the site in maintenance mode.

    That's why I implemented it as is. πŸ™‚

    Please review!

  • Pipeline finished with Failed
    2 months ago
    Total: 224s
    #286155
  • I think it would be okay to disable taking the site offline for download, for sure, since you can easily download the file afterwards at /admin/config/development/backup_migrate/backups.

    That's not true. When using Download as the destination, the backup doesn't get saved to /admin/config/development/backup_migrate/backups

  • Status changed to Needs work 2 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    @Grevil: I left some comments.

    I don't think that this is a proper fix. Instead I agree with #21:

    In other words, #20 means that we need to check if the module placed the site in maintenance mode before the backup and removed the maintenance mode before calling the exit() function.

    And of course, we need to test it

    @damienmckenna should decide, if we should go this way for now, to get 5.1.0 out and this critical one fixed and create a follow-up for the proposed solution in #21. That would be acceptable, but at least comments and @todo's should be added then, linking the follow-up.

    @damienmckenna how should we proceed here?

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    PS: Thanks for adding the important test, that the front page is still functional.

    Is there already a test available to check the resulting backup for consistency? (Not being broken like before)? Then we should also add that one for all backup tests, I think!

    If not, we should have a follow-up to implement one to save us from dangerous broken / corrupted backups?
    BTW I'd indeed vote to fix it like this for now and have two follow-ups to reduce the risky impact of this bug asap. But let's wait for Damien's feedback!

  • πŸ‡©πŸ‡ͺGermany Grevil

    The exit(); is simply readded. It was originally removed through #3180214: Site does not switch out of maintenance mode after backup finished β†’ :
    https://git.drupalcode.org/project/backup_migrate/-/commit/790cdc405d646...

    There is already a follow-up issue, where this can be solved cleanly:
    πŸ› Problem with "advanced backup" when checking destination "download" and "take site offline" Active .

    I made a comment for this!

  • Status changed to Needs review 2 months ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    Alright, adjusted the comments, please do a final review!

  • Pipeline finished with Success
    2 months ago
    Total: 199s
    #287086
  • Pipeline finished with Success
    2 months ago
    Total: 208s
    #287088
  • Status changed to RTBC 2 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    The exit(); is simply readded. It was originally removed through #3180214: Site does not switch out of maintenance mode after backup finished

    Yes, that shows the importance of the comment to explain, why it should _not_ be removed.

    Thanks for the fixes and the follow-up! I'm setting this RTBC to push this important fix forwards, but as of #51 and #52 let's wait for Damien's final feedback and decision how to proceed.

  • πŸ‡©πŸ‡ͺGermany Grevil

    I definitely vote for fixing this issue right now. We already implemented a temporary workaround, so that enabling "take site offline" and setting destination to "download" will throw a validation error. And we can follow up everything else in πŸ› Problem with "advanced backup" when checking destination "download" and "take site offline" Active .

  • Status changed to Needs work 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    This looks really good, thank you.

    A small nitpick: any URLs should be noted on separate lines with a @see prefix.

  • Status changed to Needs review 2 months ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    Done!

  • Pipeline finished with Success
    2 months ago
    Total: 200s
    #287246
  • Is there already a test available to check the resulting backup for consistency? (Not being broken like before)?

    I don't think so. It would be nice to have something check that the resulting backup actually works. I have occasionally found backup files that contain multiple INSERT statements with the same primary key, causing restore to fail. This could be due to site use during the creation of the backup. No test was added to ensure that the gzipped backup file is valid, either (that it doesn't contain trailing HTML, making it an invalid file).

  • πŸ‡©πŸ‡ͺGermany Grevil

    @solideogloria Thanks!

  • Status changed to RTBC 2 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Nitpick from #57 solved! :)

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    Excellent work, thanks everyone!

  • πŸ‡©πŸ‡ͺGermany Grevil

    Thanks, Damien! πŸ™‚

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024