Skip to content
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

Backup to S3 using Laravel 5 system doesn't appear to work #34

Closed
olimorris opened this issue Apr 29, 2015 · 9 comments
Closed

Backup to S3 using Laravel 5 system doesn't appear to work #34

olimorris opened this issue Apr 29, 2015 · 9 comments

Comments

@olimorris
Copy link

Trying to backup my site to Amazon S3 doesn't appear to work and throws this error:

[Aws\S3\Exception\BucketAlreadyOwnedByYouException]                                 
  Your previous request to create the named bucket succeeded and you already own it.

Yet, when I run the following code in my application:

Route::any('/', function() {
    Storage::disk('website-backups')->put('help.txt', 'help.txt');

    if(Storage::disk('website-backups')->exists('help.txt'))
        return "Assert true";

    return "Assert this shizzle failed";

});

I assert true, that a file called 'help.txt' was created.

@freekmurze
Copy link
Member

I can't reproduce this. Could you give me the entire debugtrace?

@olimorris
Copy link
Author

How do I do that in the Terminal?

@freekmurze
Copy link
Member

You could catch the exception in the code of your application

Route::any('/', function() {
    try {
        Storage::disk('website-backups')->put('help.txt', 'help.txt');

        if(Storage::disk('website-backups')->exists('help.txt'))
            return "Assert true";

        return "Assert this shizzle failed";
    }
    catch(Exception $e)
    {
        echo $e->getMessage().'----'.$e->getTraceAsString();
    }

});

@olimorris
Copy link
Author

Sorry, yes when I run the code above in routes.php it works fine. The issue is when I run backup from the command line and I get the following error:

[Aws\S3\Exception\BucketAlreadyOwnedByYouException]                                 
  Your previous request to create the named bucket succeeded and you already own it.

Within filesystems.php, my disk is setup as below:

'website-backups' => [
            'driver' => 's3',
            'key'    => env('S3_ACCESS_KEY'),
            'secret' => env('S3_SECRET_KEY'),
            'region' => '',
            'bucket' => 'backup-of-website',
        ],

When I add 'eu-west-1' as my region, I can still run the code in routes.php fine however I get this error when I run backup from the command line:

[Aws\S3\Exception\S3Exception]
The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.

@freekmurze
Copy link
Member

Maybe there's something wrong with your environment detection when using the CLI. Can you check on the command line (with php artisan tinker) if Config::get('filesystems');, Config::get('laravel-backup'); and App::environment(); return the right values?

@olimorris
Copy link
Author

It's most odd. Using tinker I can see the config's are being read correctly and my environment variables are being substituted in at the right places etc and my environment is set at local as per my .env.

I've tried changing my bucket permissions on AWS so that everyone can upload to it and still the same issue remains. Are your filesystem configs any different to mine?

@freekmurze
Copy link
Member

I'm using the latest version of the package and backing up to s3 works fine

~ php artisan backup:run --only-db
Start backing up
Database dumped
Start zipping 1 files...
Zip created!
Start uploading backup to s3-filesystem...
Backup stored on s3-filesystem in file "backups/20150506233035.zip"
Backup successfully completed

In config/filesystems.php S3 is configured like this:

's3' => [
    'driver' => 's3',
    'key'    => env('S3_KEY'),
    'secret' => env('S3_SECRET'),
    'region' => 'eu-west-1',
    'bucket' => env('S3_BUCKET')
],

I'm really puzzeled why it isn't working at your end. Are you sure you created the bucket on AWS in the region you specified in your config file?

@olimorris
Copy link
Author

Finally...It seems that the region was correct but I changed my path config in laravel-backup.php to be 'path' => '/backups' and that did the trick!

Really bizarre, seems like AWS didn't like putting files in the root of the bucket in this instance.

Cheers for your help Freekmurze! Oh and keep up the great posts on murze.be by the way!

@freekmurze
Copy link
Member

No problem! I'm glad you could solve this issue.

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

2 participants