composer create-project laravel/laravel example-app
php artisan serve
composer require spatie/laravel-backup
To publish the config file to config/backup.php run:
php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"
'connections' => [
'mysql' => [
'driver' => 'mysql',
'dump' => [
'dump_binary_path' => 'C:/xampp/mysql/bin/', // only the path, so without `mysqldump` or `pg_dump`
'use_single_transaction',
'timeout' => 60 * 5, // 5 minute timeout
],
],
],
MAIL_MAILER=smtp
MAIL_HOST=sandbox.smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
php artisan backup:run
If you only need to backup the db, run:
php artisan backup:run --only-db
If you only need to backup the files, and want to skip dumping the databases, run:
php artisan backup:run --only-files
php artisan backup:clean
Install Google drive filesystem extension
composer require masbug/flysystem-google-drive-ext
GOOGLE_DRIVE_CLIENT_ID=
GOOGLE_DRIVE_CLIENT_SECRET=xxx
GOOGLE_DRIVE_REFRESH_TOKEN=xxx
GOOGLE_DRIVE_FOLDER=Backups
'google' => [
'driver' => 'google',
'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
'folder' => env('GOOGLE_DRIVE_FOLDER'),
],
public function boot(){
try {
\Storage::extend('google', function($app, $config) {
$options = [];
if (!empty($config['teamDriveId'] ?? null)) {
$options['teamDriveId'] = $config['teamDriveId'];
}
$client = new \Google\Client();
$client->setClientId($config['clientId']);
$client->setClientSecret($config['clientSecret']);
$client->refreshToken($config['refreshToken']);
$service = new \Google\Service\Drive($client);
$adapter = new \Masbug\Flysystem\GoogleDriveAdapter($service, $config['folder'] ?? '/', $options);
$driver = new \League\Flysystem\Filesystem($adapter);
return new \Illuminate\Filesystem\FilesystemAdapter($driver, $adapter);
});
} catch(\Exception $e) {
// your exception handling logic
}
}
'destination' => [
'disks' => [
// 'local', change local to google
'google',
],
],
Create a folder named "Backups" in your google drive. Then create another folder named "Laravel" into this Backups folder. This "Laravel" name should be same as storage/app/Laravel
php artisan backup:run