backdrop-contrib / backup_migrate

Port of the Drupal backup_migrate module to Backdrop
GNU General Public License v2.0
7 stars 14 forks source link

Add region configuration in the S3 destination settings #65

Open sillygwailo opened 3 years ago

sillygwailo commented 3 years ago

I have an S3 bucket that I back up to that's in the ca-central-1 AWS region, and it won't back up, and I get this error, because the library assumes the us-east-1 AWS region:

User warning: S3::putObject(): [AuthorizationHeaderMalformed] The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'ca-central-1' in S3::__triggerError() (line 440 of /var/www/b/libraries/amazon-s3-php-class/S3.php).

That error is from the S3 library, but I got around it by hacking the module and hard-coding it:

--- a/includes/destinations.s3.inc
+++ b/includes/destinations.s3.inc
@@ -172,6 +172,7 @@ class backup_migrate_destination_s3 extends backup_migrate_destination_remote {
         require_once $path . '/S3.php';
         if (!$this->s3 && !empty($this->dest_url['user'])) {
           $this->s3 = new S3($this->dest_url['user'], $this->dest_url['pass']);
+          $this->s3->setRegion('ca-central-1');
         }
         return $this->s3;
       }

https://www.drupal.org/project/backup_migrate/issues/3027843#comment-13236642 has a patch for the D8 version of the module that seems to add a region field, which is what I'd ultimately prefer.