Skip to content

Instantly share code, notes, and snippets.

@escuccim
Created January 30, 2017 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save escuccim/49624ef1a752ad8336215c7fe9f06075 to your computer and use it in GitHub Desktop.
Save escuccim/49624ef1a752ad8336215c7fe9f06075 to your computer and use it in GitHub Desktop.
Laravel Command to Backup File to Amazon S3
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Aws\Laravel\AwsFacade as AWS;
class BackupDB extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'backup:db {file}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Uploads DB dump to Amazon S3';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$file = $this->argument('file');
$s3 = AWS::createClient('s3');
$s3->putObject(array(
'Bucket' => env('AWS_BUCKET'),
'Key' => 'database/dumps/' . $file,
'SourceFile' => public_path() . '/storage/dumps/' . $file,
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment