Backup Destinations
Google Drive
A guide on how to set up Google Drive as a cloud destination for Craft Remote Backup
Overview
Google Drive is one of the more difficult destinations to configure. You need to configure a new Google Cloud Console project (which may require setting up an account and adding payment details), then enable the "Drive API", then configure credentials and finally go through the OAuth flow to allow Remote Backup access to your Google Drive.
Setup
To use Google Drive, first make sure to install the official PHP SDK google/apiclient:^2.0:
composer require google/apiclient:"^2"
Setup Google Drive
Go the developer documentation for details on how to get access to the Drive API.
Follow this link in the Google Documentation to create a new project in the Google Cloud Console. Briefly, the steps are:
- Open the Google Cloud Console
- Click the top-left hamburger menu and go to "IAM & Admin > Create a Project."
- Click "Create".
- Give it a name. You can ignore the other fields.
Next enable the "Drive API".
- Click the top-left hamburger menu again and this time go to "APIs & Services > Library".
- Click "Enabled APIs & Services" in the left-hand menu, then "Enable APIs and Services" button up-top.
- Search for "Drive API" then click "Google Drive API"
- Click "Enable"
Next you need to configure credentials.
Click "Credentials" and then "Create Credentials"

Select "OAuth Client ID":

- At this point, you might be asked to "configure consent screen"
- Add an "App name", "User support email" and "Developer contact information"
- You can skip the "Scopes" and "Summary" pages
- Go back to the "Credentials" screen once created
- Select "Web application":


Make sure to add the redirect URL. This should look like:
https://craft-4-plugins-test.ddev.site/admin/remote-backup/google-drive/auth-redirect
Where craft-4-plugins-test.ddev.site matches the hostname of the server you are backing up from. For example, if you want to use this in production, this should be domain to your production site.

Make sure to download the JSON file. It should look something like this:

Configure Remote Backup
We now need to add our credentials to Remote Backup. The easiest way to do this is to open the credentials.json that you downloaded from the previous step and add the values your project's .env file:
GOOGLE_DRIVE_CLIENT_ID="..."
GOOGLE_DRIVE_CLIENT_SECRET="..."
GOOGLE_DRIVE_REDIRECT_URL="https://craft-4-plugins-test.ddev.site/admin/remote-backup/google-drive/auth-redirect"
GOOGLE_DRIVE_PROJECT_NAME="..."
GOOGLE_DRIVE_CLIENT_IDis theclient_idfrom thecredentials.jsonGOOGLE_DRIVE_CLIENT_SECRETis theclient_secretGOOGLE_DRIVE_CLIENT_SECRETis theproject_idGOOGLE_DRIVE_REDIRECT_URLis the URL that Google will redirect back to after OAuth is complete. The only change you should make here is the port. I'm using MAMP which runs all my local projects on 8888. The host and path must match the above example.
Now open the Remote Backup setting page and connect these environment variables:

See the "Folder Configuration" section below for more on the last setting.
Authenticate via OAuth
Click the "Authenticate with Google Drive" button down the bottom of the settings page. This will bring you to an another auth page. Hit "authenticate":

This will take you to Google to start the OAuth flow.

You should be returned to the /admin/remote-backup/google-drive/auth-redirect path which should display a success message:

In the background, a new token file has been saved to storage/remote-backup/google-drive-remote-backup-token.json which will be used to connect to Google Drive.
Folder Configuration
You can configure the folder within your Google Drive to send backups using the "Google Drive Folder ID" setting.

This can be:
- a folder within your personal Google Drive
- a team drive
- a folder within a team drive
To configure this, you need to get the ID of the folder you want to use. The easiest way to do this is to log in Google Drive and navigate to the folder you want to use. Then grab the ID from the URL bar:

Troubleshooting
Here are some troubleshooting specs specifically for the Google Drive integration. If you're still having trouble, see the troubleshooting section to get in touch. Please include details on how you're Google Drive is configured (personal drive or shared drive, what folder the backups are in etc.) as well as any relevant logs.
Check Credentials are Correct
- If you are encountering errors, first double check the credentials entered from the JSON file you downloaded from the Cloud Console.
- If you are using a specific folder, make sure the folder ID is correct.
- If using a shared drive, also make sure the folder is accessible from your account.
Reset Google Auth Credentials
If you are continuing to having trouble, try delete the file storage/remote-backup/google-drive-remote-backup-token.json from your site directory and then re-authenticate with Google via the Remote Backup settings page


