When you set up s3fs to take over the private file system, the backup_migrate module will accept it and write to the s3fs-private folder in your S3 bucket, but it will not read from that bucket in order to perform a restore.

This may very well be a "won't fix", as backup_migrate can be configured to use an S3 bucket as a destination. However, I thought you might want to note it as a limitation in the takeover of the private file system.

The file is there:

% aws s3 ls s3://s3_bucket_name/s3fs-private/backup_migrate/manual/
2015-01-27 15:42:20    4839622 SiteName-2015-01-27T15-41-56.mysql.gz
2015-01-27 15:42:20        406 SiteName-2015-01-27T15-41-56.mysql.gz.info

But it does not appear in the saved files list:

Here's my other file system and s3fs config:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

coredumperror’s picture

I'll look into this. It may be a bug in s3fs, but I think (showing my bias here), that it's more likely to be a bug in Backup and Migrate.

John Bickar’s picture

Thanks. Using backup_migrate-7.x-3.0 and the January 13th 7.x-2.x-dev of s3fs. Also using file_entity-7.x-2.0-alpha3, if that matters.

I did not attempt to re-create on simplytest.me with a clean install, so it's possible that it's something with my config.

coredumperror’s picture

Project: S3 File System » Backup and Migrate
Version: 7.x-2.x-dev » 7.x-3.x-dev
FileSize
1.17 KB

Yup, this is a bug in Backup and Migrate. In several places, Backup and Migrate's code calls the drupal_realpath() function to convert from a stream uri (e.g. private://backup_migrate/manual) to an absolute local filesystem path. That works fine with the usual private:// stream, since it maps to a real location on the server's local filesystem. But since there's no such thing as a realpath for a file in S3, S3fsStreamWrapper->realpath() always returns FALSE. This breaks the function that lists all the available backup files, which is why you get an empty list.

I've attached a quick-and-dirty patch that simply removes the majority of relevant uses of drupal_realpath(). I have no idea what kind of knockon effect this will have, but it does allow files in s3 to be listed in the Saved Backups tab.

I'm going to move this issue to the Backup and Migrate queue, since it really shouldn't be calling drupal_realpath() at all. The docs even specifically discourage its use, for this exact reason.

taw.boston’s picture

Moving my comment to correct version...

ronan’s picture

Category: Bug report » Support request
Status: Active » Needs work

I throw my hands up in the air at an API function where the first line of the documentation is "Don't use this function"

Seriously though. There are a lot of realpath calls and every one of them is in response to a ticket where somebody's weird setup required it to work. The files directory can be inside the webroot, outside the webroot, it can be a symlink, it can be absolutely defined or relatively or it can be a combination of all these things. Removing the realdir calls will cause regressions that will take years to surface. I'm afraid I'm going to have to favor the 99% use case here where the private directory is local to the server.

If someone can find a simple way of supporting remote streams for the file directory that doesn't break the million other cases that I need to support I'd love to include that, but I'm not sure that should be even undertaken without some sort of automated test coverage.

John Bickar’s picture

That gives me no heartburn :)

This is a real edge case; I initially opened the issue against s3fs just in case there was an oversight or bug in that module.

Feel free to set as "won't fix" - there's already an option to use backup_migrate to back up to S3.

Thanks for the great module.

coredumperror’s picture

Maybe you could write a wrapper function around drupal_realpath() that returns the original URI when drupal_realpath() returns FALSE? That shouldn't affect any existing use cases with local filesystems, since drupal_realpath() only returns FALSE if it fails to resolve the real path.

blake.thompson’s picture

I've run into this issue as well. Here's a patch with a poor man's implementation of @coredumperror's idea, it seems to do the job.

DamienMcKenna’s picture

Status: Needs work » Needs review

The last submitted patch, 3: backup_migrate-no_realpath.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

joelpittet’s picture

ron_s’s picture

Status: Needs review » Reviewed & tested by the community

Just ran into this problem and #8 seems to do the job. Performed a manual backup via s3fs, and the file was successfully generated, but no items listed on the "Saved Backups" tab.

After applying the patch, the backup is displayed and able to download it. Thanks for the effort!

ron_s’s picture

Couple of small adjustments... the patch isn't formatted as it should be. Also it's trying to automatically fix extra spaces elsewhere in the module.

Here is an updated version that only includes the relevant code, formatted appropriately. Works as advertised.

ron_s’s picture

One more update. I don't like running the same function on consecutive lines when it has already been evaluated. It's unnecessary processing overhead.

Changed the conditional to capture the result in a variable instead.

DamienMcKenna’s picture

Status: Reviewed & tested by the community » Needs review

Would appreciate a review on the latest patch. Thanks.

ron_s’s picture

I understand wanting to have someone review the update, although the changes I made are *really* minor, and this is a very small patch.

If you want to revert to patch #8 which I already tested and found that it worked correctly, we can do so. However it seems a bit silly given that #14 is just a slightly more efficient version of #8.

joelpittet’s picture

@ron_s an interdiff goes a long way to show the minorness of a change.
https://www.drupal.org/documentation/git/interdiff

ron_s’s picture

@joelpittet, I know all about interdiffs. I've created many of them, and so have people in my company. Three comments:

1) Patch #8 no longer applies cleanly to 7.x-3.x-dev, so it's not an option. And I'm not going to dig around trying to find an old version of -dev to create a pseudo-interdiff.

2) A patch is cleaned up that sat idle for 3+ years, and contains literally 8 lines of code. The feedback is more review is necessary and maybe an interdiff should be created. At what point does the Drupal community willingly accept what they receive from those trying to help?

3) I'm all for following standards, and certainly believe in the importance of interdiffs. However, I'm wondering when (if ever) the Drupal community will decide to inject some common sense into its decision making. Things like this drive people away from contributing.

DamienMcKenna’s picture

Status: Needs review » Reviewed & tested by the community
Parent issue: » #2942331: Plan for Backup and Migrate 7.x-3.6

Thanks for the explanation in #16, ron_s. An interdiff on this isn't needed.

DamienMcKenna’s picture

FYI I want to test this on a few instances before committing it, just to make sure there aren't any regressions when not using S3.

joelpittet’s picture

@ron_s Sorry I didn't mean to offend and probably shouldn't have written anything as I've seen your name in many places and could have guessed you already knew how to make them. I read the

although the changes I made are *really* minor,

and that was the trigger for the reaction comment to keep things moving. Again, my sincere apologies!

ron_s’s picture

No worries @joelpittet. I should have been more explicit and said the changes made were only cleanup. The approach was not modified.

The only change I made was to modify this in the patch...

+     if (drupal_realpath($this->get_location())) {
+       return drupal_realpath($this->get_location());
+     }

into this...

+    if ($realpath = drupal_realpath($this->get_location())) {
+      return $realpath;
+    }

I would hope we can agree the second is more efficient than the first, since drupal_realpath doesn't have to run twice.

joelpittet’s picture

Completely agree it's more efficient. I'm not personally a fan of assignments in conditionals, but that debate is happening elsewhere and I wouldn't hold up this issue on that.

RTBC++, thanks @ron_s and @DamienMcKenna

ron_s’s picture

Ah I hadn't see this thread before: https://www.drupal.org/project/coding_standards/issues/2907332

I'd have to say I'm a "0" on the issue. I understand the pros and cons, but not strongly opinionated about it.

DamienMcKenna’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks.

Status: Fixed » Closed (fixed)

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