- If you have not already set up a Google Drive account, you must do so before following the procedures below. To set up a Google Drive account, please visit https://www.google.com/drive.
- You can configure Google Drive backups on any hosting.com plan.
- Google has changed the process for creating Google API credentials. As a result, the Google Drive configuration process now requires completing multiple procedures. Make sure you follow the procedures below in the order in which they appear.
Step 1: Create Google API credentials
First you must create a set of Google API credentials. At the end of this procedure, you will have a Client Id and Client Secret to use with the gdrive command-line program. The gdrive program enables you to access and manipulate Google Drive files and directories from the command line. To create Google API credentials for your account, follow these steps:- Log in to the Google Cloud Console with your Google Mail account at https://console.cloud.google.com/.
-
Click the project list box, and then click NEW PROJECT:
-
In the Project name list box, type a name for the project. In this procedure, we use the gdrive-example project name:
- Click CREATE.
-
In the search bar, type
drive api, and then under MARKETPLACE, click Google Drive API:
-
Click ENABLE:
-
Click the CREDENTIALS tab:
-
Click CONFIGURE CONSENT SCREEN:
-
Under User Type, click External, and then click CREATE:
-
In the App name text box, type
gdrive-example:
- In the User support email list box, select your Google account.
- In the Developer contact information text box, type the email address for the developer.
- Click SAVE AND CONTINUE.
-
Click ADD OR REMOVE SCOPES:
-
In the Filter text box, type
google drive api, and then click Google Drive API:
-
Select the ../auth/drive check box and ../auth/drive.metadata.readonly check box:
-
Click UPDATE, and then click SAVE AND CONTINUE:
-
Click ADD USERS:
-
In the text box, type the email address for your Google account, and then click ADD:
-
Click SAVE AND CONTINUE:
-
In the left sidebar, click Credentials:
-
Click CREATE CREDENTIALS, and then click OAuth client ID:
-
In the Application type list box, select Desktop app:
-
In the Name text box, type
gdrive cli. -
Click CREATE. The Client ID and Client secret appear. Click the clipboard icons to copy them, and then save them in a file. You will need these values later during the configuration process:
- Click OK.
-
In the left sidebar, click OAuth consent screen, and then click PUBLISH APP:
-
In the Push to production? dialog box, click CONFIRM:
-
Under Publishing status should appear In production:
You can ignore the Needs verification warning in the Verification Status section. Gdrive functions normally without verification.
Step 2: Install the gdrive program on your local computer
After you create Google API credentials, you are ready to install the gdrive program on your local computer. The gdrive program enables you to access and manipulate Google Drive files and directories from the command line.To add an account to gdrive, you must use a web browser during the initial setup process. However, the command-line environment on the server does not have a web browser. To work around this problem, you add the account to gdrive on your local computer, export the configuration, and then import that configuration into your hosting.com account on the web server. The following procedures demonstrate how to do this.
- In your web browser, go to https://github.com/glotlabs/gdrive/releases.
- Download the correct file for your operating system:
- Linux: gdrive_linux-x64.tar.gz
- Apple macOS: gdrive_macos-x64.tar.gz
- Microsoft Windows: gdrive_windows-x64.zip
The most recent version when this article was published was 3.9.0.
- Decompress the compressed .tar.gz or .zip file to obtain the gdrive executable program.
- Open a command prompt (terminal) window in the directory where you extracted the downloaded file.
- To ensuregdrive works, type one of the following commands:
- For Microsoft Windows:
- For Linux and macOS:
Step 3: Add your Google account to gdrive
After you installgdrive on your local computer, you are ready to add your Google account to the gdrive configuration. To do this, follow these steps:- Open a command prompt (terminal) window.
- At the command prompt, type the following command:
- At the Client ID prompt, type (or copy and paste) the Client ID you obtained when creating Google API credentials.
- At the Client secret prompt, type (or copy and paste) the Client secret you obtained when creating Google API credentials.
-
A URL appears. Open the URL in your web browser. You receive the Google hasn’t verified this app message:
-
Click Advanced, and then click Go to gdrive-example:
-
Select the Select all check box, and then click Continue:
- At the command prompt, type the following command:
Step 4: Export the gdrive account configuration and upload it to the hosting.com server
Now that your Google account is configured ingdrive, you are ready to export the configuration and upload it to your hosting account on the hosting.com server. To do this, follow these steps:- On your local computer, open a command prompt (terminal) window.
- At the command prompt, type the following command. Replace email-address with the email address of your Google account:
- The previous step generates a .tar file. Using FTP or SCP, upload the .tar file to your hosting.com account on the remote server.
Step 5: Install the gdrive program on your hosting.com account
You are now ready to install the gdrive program on your hosting account and import the configuration you uploaded in the previous procedure. To do this, follow these steps:- Log in to your hosting.com account using SSH.
- At the command prompt, type the following commands to download and extract the gdrive program:
- To make the gdrive program accessible from any directory in your account, type the following commands:
- To confirmgdrive is installed correctly, type the following command:
- To import the account configuration, type the following command. Replace filename with the name of the .tar file you uploaded in the previous procedure:
Step 6: Back up data to Google Drive
After you install and configure the gdrive program, and have verified thatgdrive can connect to Google Drive, you are ready to:- Create a directory on Google Drive to contain your backup files.
- Create a cron job on your hosting account to do the actual backup.
- To create a directory on Google Drive in which to store your backup files, type the following command. You can replace backups with any name you want to use:
- To verify that the directory was created successfully, type the following command:
- After you verify that the Google Drive directory was created successfully, you are ready to set up a cron job that backs up files to the directory automatically. To do this, the cron command must run the gdrive program with the correct ID of the destination directory.For example, the following cron command demonstrates how to back up the entirepublic_html directory to the Google Drivebackups directory daily at 2:30 AM. Replace username with your own hosting.com account username, and replace ID with the ID of the backups directory:
Step 7 (optional): Restore data from Google Drive
To restore data from Google Drive to your hosting.com account, follow this step:- Use the gdrive files download commands:
- To restore an individual file, type the following command. Replace ID with the ID of the file you want to restore:
- To restore an entire directory, type the following command. Replace ID with the ID of the directory you want to restore:
More information
- For general information about Google Drive, please visit https://www.google.com/drive.
- To view the official Google Drive documentation, please visit https://support.google.com/drive.