Laravel 8 Backup Store On Google Drive Example

In this tutorial you will learn about the Laravel 8 Backup Store On Google Drive Example and its application with practical example.

In this Laravel 8 Backup Store On Google Drive Example I will show you how to take laravel site backup in google drive. In this tutorial I will also show you how to integrate google drive in laravel 8 to store backup on google drive. In this example we will learn Google Drive integration in Laravel 8. In this example we will be using spatie/laravel-backup package to take backup in google drive.

Laravel 8 Backup Store On Google Drive Example

In this step by step Laravel 8 Backup Store On Google Drive Example I will demonstrate you how to integrate google drive in laravel site to take site backup. Please follow instructions given below:

  • Step 1 – Setup Google Drive Account
  • Step 2 – Install Laravel 8 App
  • Step 3 – Connecting App to Database
  • Step 4 – Install spatie/laravel-backup
  • Step 5 – Setup Google Drive as Filesystem in Laravel
  • Step 6 – Configure Google Drive Details
  • Step 7 – Execute Backup Command

Step 1 – Setup Google Drive Account

Before integrating Google Drive in laravel 8. that you have google client id and secret id,  refresh token and folder id. Please follow the instruction given below. You can create Google App in Google Developer Console by following the steps given below.

Step 1 – Visit the link given below and create a new project:

Step 2 – Visit “Library” of google search console and search for “Google Drive API“:

Step 3 – Then enable the Google Drive API.

Step 4 – Now, Visit “Credentials” and click on the tab “OAuth Consent Screen”. Here you will get options to select user type, select “External” option, and click the “CREATE” button.

Step 5 – Please provide following details like “App Name“, “User support email” and “Email” in the Developer contact information and click Save And Continue button. For other forms “Scopes“, “Test Users” and “Summary” click on Save And Continue button and go to the dashboard. Don’t worry about the other fields.

Step 6 – Now, on OAuth consent screen, you will see that the App’s Publishing status is testing. Click the Publish App button and confirm.

Step 7 – Now, visit Credentials and click the button that says “Create Credentials” and select “OAuth Client ID“.

Step 8 – For “Application type” choose “Web Application” and give it a name. You also need to provide your “Authorized redirect URIs”.

Step 9 – Now visit the below link:

In the top right corner, click the settings icon, check “Use your own OAuth credentials” and paste your Client ID and Client Secret.

Step 10 – on the left, scroll to “Drive API v3”, expand it, and check each of the scopes. Click “Authorize APIs” and allow access to your account when prompted.

Step 11 – You also need to check “Auto-refresh the token before it expires” and click “Exchange authorization code for tokens“.

Step 12 – Now, complete this step and click on step 1 again and you should see your refresh token.

Step 13 – Now you need folder ID that is optional. If you set folder ID to null, in that case, it is going to store backup files in the root path of Google Drive. You can get the folder ID from the URL.

Step 2 – Install Laravel 8 App

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Step 3 – Connecting App to Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 4 – Install spatie/laravel-backup

In this step run the following command to install spatie/laravel-backup package in laravel 8:

Now, run the following command to publish this installed package:

Now, you need to add google in the disk option in the config/backup.php.

Step 5 – Setup Google Drive as Filesystem in Laravel

Now, you need to run the following command to install a Filesystem adapter for Google drive:

Now, inside the boot() method add the Google driver for the Laravel filesystem:

app/Providers/GoogleDriveServiceProvider.php

Now, you need to register the service provider toproviders array of config/app.php.

Step 6 – Configure Google Drive Details

In this step, you need to configure Google drive app with this laravel app. Go to the config directory and open filesystem.php file and add the client id, secret and callback url:

You also you need to update .env file of laravel 8 app. Please add the following Google drive credentials:

Step 7 – Execute Backup Command

In this step we are ready to take backup run the following command to check the backup file is created or not:

In this tutorial we have learn about the Laravel 8 Backup Store On Google Drive Example and its application with practical example. I hope you will like this tutorial.