Created
January 30, 2017 15:04
-
-
Save escuccim/49624ef1a752ad8336215c7fe9f06075 to your computer and use it in GitHub Desktop.
Laravel Command to Backup File to Amazon S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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