Skip to content

Using S3, not possible to write direct to bucket #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
snapey opened this issue Dec 8, 2015 · 5 comments
Closed

Using S3, not possible to write direct to bucket #55

snapey opened this issue Dec 8, 2015 · 5 comments

Comments

@snapey
Copy link

snapey commented Dec 8, 2015

I create S3 bucket dedicated for the backup and use IAM to provide permission to write to bucket.

Unfortunately it is not possible to set path='' to tell laravel-backup to write to the root of the bucket. Any slashes are removed and key is detected as being 0 characters long.

All works ok if folder is named but it mandates an extra folder level that otherwise is not required.

@freekmurze
Copy link
Member

I've made a fix for this in de dev-master version of this package. Could you try if this fix solves the problem?

@snapey
Copy link
Author

snapey commented Dec 15, 2015

I copied the revised function getBackupDestinationFilename

Line 192, I had to add a semi-colon

I then set path to empty string.

AWS is throwing an error;

  [Aws\S3\Exception\S3Exception]
  Error executing "PutObject" on "https://s3-eu-west-1.amazonaws.com/myproject/"; AWS HTTP error: Client error response [url] https://s3-eu-west-1.amazonaws.com/myproject/ [status code] 400 [reason p
  hrase] Bad Request IllegalLocationConstraintException (client): The unspecified location constraint is incompatible for the region specific endpoint this request was sent to. - <?xml version="1.0
  " encoding="UTF-8"?>
  <Code>IllegalLocationConstraintException</Code><Message>The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.</Message>

I'll research this further but not today.

@snapey
Copy link
Author

snapey commented Dec 23, 2015

The IllegalLocationConstraintException seems like a bug at AWS. There is very little online about this and the error is not one of those listed in the S3 API.

After some testing, I tracked the problem to the first two lines of the copyFile function in BackupCommand.php

    protected function copyFile($file, $disk, $destination, $addIgnoreFile = false)
    {
        $destinationDirectory = dirname($destination);

        $disk->makeDirectory($destinationDirectory);

When specifying a path in the config, dirname returns the name of the folder and makeDirectory ensures that this folder exists.

When the destination.path is empty, dirname returns a period "."

When makeDirectory is called with period as the directory name, AWS throws the exception.

A workaround is to skip the makeDirectory call when dirname returns a period.

        if ($destinationDirectory!='.') {
            $disk->makeDirectory($destinationDirectory);
        }

This should not affect other filesystems and I have tested with local and this is fine.

@michellaurent
Copy link

I had the same issue but the fix proposed by @snapey doesn't solve it in my case.

If destination.path is empty ($path = ''), dirname returns a slash "/"

When makeDirectory is called with slash as the directory name, AWS throws the exception.

[InvalidArgumentException]
Found 1 error while validating the input provided for the PutObject operation:
[Key] must be at least 1 characters long. Value provided is 0 characters long.            

A workaround is to skip the makeDirectory call when dirname returns a slash.

if ($destinationDirectory != '/') {
    $disk->makeDirectory($destinationDirectory);
}

I have tested with local on homestead and forge with local and s3 filesystems.

@michellaurent
Copy link

Tested again on the latest 2.9.0, and what @snapey said is right and solved the issue.

Made pull request #62 with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants