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 #3257316: Backup files contain trailing HTML, corrupts archive backups for more debugging progress prior to this issue and possible issue credits.
| Comment | File | Size | Author |
|---|---|---|---|
| #36 | backup_migrate-3228379-m29.patch | 4.45 KB | solideogloria |
| #19 | 3228379-download-errors-19.patch | 587 bytes | jillh68 |
| #14 | 3228379-download-returning-response-14.patch | 1.13 KB | slejnej |
Issue fork backup_migrate-3228379
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
damienmckennaAre you using user 1 to access this page or a different user?
Comment #3
jeffwpetersen commentedAll Users.
Comment #4
sassafrass commentedI have this issue as well.
Comment #5
josweb commentedI am experiencing the same issue.
Comment #6
suryantoI have this issue as well using Drupal 9.2.7
Comment #7
danyg commentedIs there any updates with it? I'm facing with the same on our Production site but I cannot reproduce it on my local environment.
Drupal 9.1.3
Backup and Migrate 5.0.1
Comment #8
chris dart commentedI'm encountering this error, but it's not related to permissions. I am using Drupal 9.2.10, backup_migrate 5.0.1. After the file is created in the /private or /tmp directory, there's an error I can't seem to back-trace. The error definitely happens after the file is generated on the server (So after
/modules/contrib/backup_migrate/src/Controller/BackupController.phpBackupController::download()) All I get is this information:If I create field with a file field that uploads to the private directory, it doesn't have any trouble downloading the file. So there's no trouble translating private files to viable downloads. The browser experience is that it shows the file being downloaded, and then after it's completed, it shows the "Failed Network Error" over the icon (in Chrome).
There's another error that occurs that I can't tell is related, but happens every time I run the download.
Comment #9
chris dart commentedI would be interested in fixing this bug if I can get some help and direction.
Comment #10
jeffwpetersen commentedFor me this issue was happening on our server setup on AWS with kubernettes. I did not have a problem on standard hosting server systems.
Comment #11
chris dart commentedWe discovered that our issue was with a broken varnish pod in our K8s cluster. Not sure if this information will help others with this problem, but it is now resolved for us.
Comment #12
jamesgrobertson commentedI seem to be able to download the file from my local environment, but not a remote environment.
It looks like
\Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::wrapControllerExecutionInRenderContext()is returningNULL, so that's where I'm going to start debugging.Comment #13
jamesgrobertson commentedIt looks like there is a todo in
\Drupal\backup_migrate\Drupal\Destination\DrupalBrowserDownloadDestination::saveFileto refactor to use a Symfony response. It seems like that's necessary from the error message we're getting. I'm not quite sure how to do that, but I can try!Comment #14
slejnej commentedSame issue on Drupal9 with 5.0.1. We had the issue only on AWS EC2 instance and not on linode. Both servers have php 7.4
The error clearly says it is missing a required Response and the function download() is not returning any.
@chris-dart Simple patch that fixes the issue.
Comment #15
damienmckennaThanks for providing the patch, let's see what the testbot thinks of it.
Comment #16
jcnventuraWell, the testbot thinks it is fine. But I still get "Failed - Network error" when downloading an SQL backup.
From what I can see in the partial crdownload file, the SQL file is sent, followed by a small piece of HTML with a redirect to https://site/admin/config/development/backup_migrate
This is most likely a returned RedirectResponse from the normal Drupal form handler. That would seem to invalidate the need for this code.
Reverting the change in #3180214: Site does not switch out of maintenance mode after backup finished fixes the problem and finishes the download.
Comment #17
jillh68 commentedFor me, downloads became html files and I was getting the error
As jcnventura suggested, reverting the change made in #3180214: Site does not switch out of maintenance mode after backup finished fixed the issue.
Comment #18
jillh68 commentedComment #19
jillh68 commentedFixed patch.
Comment #20
damienmckennaLet's expand the test coverage to make sure this problem is solved, without breaking the existing maintenance-mode functionality.
Comment #21
jcnventuraIn 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
Comment #22
cristiroma commentedI just did a manual test of the patch on hosting provider, and while it fixes the problem - the download is finished 100% - it leaves the website in maintenance mode. Here are the steps.
1. Visit /admin/config/development/backup_migrate/advanced
2. Check "Take site offline"
3. Press "Backup Now"
The SQL dump was correctly downloaded, but the website remains in the maintenance mode.
Comment #23
kvantstudio commented#19 fix problem!
Comment #24
Kashalinka commentedThe patch in #19 worked for me, too. The site did not stay in maintenance mode. All good. Thanks.
Comment #25
thirstysix commented#19 works fine.
I will do some more tests.
Comment #26
mrdrewkeller commentedPatch #19 is working for me. Site out of maintenance mode, run backup, backup completes and is downloaded, site is not in maintenance mode.
Comment #27
damienmckennaThank you for the reviews of the change. Let's add some test coverage as detailed in #21.
Comment #30
grevil commentedI 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.
Comment #31
grevil commentedSetting this to "needs review", maybe someone can fix the test.
EDIT: Of course, the backup will still be in full effect, when checking maintenance mode, so instead, we should change this test to being a JS test and wait for the success message to appear, before checking maintenance mode again.
Comment #32
grevil commentedComment #33
grevil commentedTests 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.
Comment #34
solideogloria commentedAdding related issue, since it was mentioned in #16 and #17 that downloaded files contain html.
Comment #35
solideogloria commentedAfter 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!
Comment #36
solideogloria commentedPatch for convenience.
Comment #37
solideogloria commentedBumping priority to match that of the related issue. (Backups containing trailing HTML means that backups contain data that shouldn't be there, possibly corrupting a site on restore.)
Comment #38
solideogloria commentedComment #39
solideogloria commentedComment #40
solideogloria commentedComment #42
grevil commentedJust 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.
EDIT: Whoops, already mentioned that in #33.
Comment #43
grevil commentedTaking a further look, the destinations "download" (and "upload" for some reason) are added through line 144-149 in backup_migrate.module:
I think, that is the root of the problem. Differently from the destinations "download" and "upload", the "private_files" destination 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. But since none of these destinations are plugins, they do not implement such a method nor extend the Plugin class. Instead, the "DrupalUtils" plugin will get the site back online for the private_files destination. But it only does that for the private_files destination, even though we add the DrupalUtils plugin a few lines below of the before mentioned download and upload destinations.
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.
Comment #44
solideogloria commentedComment #45
solideogloria commentedShould a test also be added to ensure that the related issue doesn't occur again? (Making sure that the downloaded backup is correct)
Comment #46
solideogloria commented@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.
Comment #47
grevil commentedDon'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).EDIT: Trash that, I misunderstood the comment by @solideogloria. As mentioned above, the test result is NOT a false positive.
Comment #48
anybody@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?
Comment #49
grevil commentedOk, 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: #3475192: Problem with "advanced backup" when checking destination "download" and "take site offline".
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!
Comment #50
solideogloria commentedThat's not true. When using Download as the destination, the backup doesn't get saved to /admin/config/development/backup_migrate/backups
Comment #51
anybody@Grevil: I left some comments.
I don't think that this is a proper fix. Instead I agree with #21:
@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?
Comment #52
anybodyPS: 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!
Comment #53
grevil commentedThe
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:
#3475192: Problem with "advanced backup" when checking destination "download" and "take site offline".
I made a comment for this!
Comment #54
grevil commentedAlright, adjusted the comments, please do a final review!
Comment #55
anybodyYes, 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 forward, but as of #51 and #52 let's wait for Damien's final feedback and decision how to proceed.
Comment #56
grevil commentedI 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 #3475192: Problem with "advanced backup" when checking destination "download" and "take site offline".
Comment #57
damienmckennaThis looks really good, thank you.
A small nitpick: any URLs should be noted on separate lines with a @see prefix.
Comment #58
grevil commentedDone!
Comment #59
solideogloria commentedI 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).
Comment #60
solideogloria commentedAdded follow-up. #3475585: Add CI tests to ensure created backups are valid
Comment #61
grevil commented@solideogloria Thanks!
Comment #62
anybodyNitpick from #57 solved! :)
Comment #63
damienmckennaExcellent work, thanks everyone!
Comment #65
solideogloria commentedYay! 🎉
Comment #66
grevil commentedThanks, Damien! 🙂