This article describes how to back up data on your A2 Hosting account to a Google Drive account, as well as how to restore data from Google Drive to your account. Using this configuration, your data is backed up securely to an off-site storage location.
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:
In the Project name list box, type a name for the project. In this procedure, we use the gdrive-example project name:
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:
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:
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:
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:
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 install gdrive on your local computer, follow these steps:
To ensure gdrive works, type one of the following commands:
gdrive version
For Linux and macOS:
./gdrive version
The version number should appear.
After you install gdrive on your local computer, you are ready to add your Google account to the gdrive configuration. To do this, follow these steps:
gdrive account add
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:
Google adds your account.
At the command prompt, type the following command:
gdrive account list
Your Google account email address should appear.
Now that your Google account is configured in gdrive, you are ready to export the configuration and upload it to your hosting account on the A2 Hosting server. To do this, follow these steps:
gdrive account export email-address
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:
cd ~ wget https://github.com/glotlabs/gdrive/releases/download/3.9.0/gdrive_linux-x64.tar.gz tar xvzf gdrive_linux-x64.tar.gz
To make the gdrive program accessible from any directory in your account, type the following commands:
mkdir ~/bin mv ~/gdrive ~/bin
To confirm gdrive is installed correctly, type the following command:
gdrive version
You should receive output that resembles the following text:
gdrive 3.9.0 Commit: unknown Rust: 1.68.0 Arch: x86_64 OS: linux
To import the account configuration, type the following command. Replace filename with the name of the .tar file you uploaded in the previous procedure:
gdrive account import filename
The Google account configuration process is now complete, and you are ready to configure backups for your A2 Hosting account.
After you install and configure the gdrive program, and have verified that gdrive can connect to Google Drive, you are ready to:
To do this, follow these steps:
gdrive files mkdir backups
To verify that the directory was created successfully, type the following command:
gdrive files list
Note the ID for the directory, as you will need this information below.
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 entire public_html directory to the Google Drive backups directory daily at 2:30 AM. Replace username with your own A2 Hosting account username, and replace ID with the ID of the backups directory:
30 2 * * * /home/username/bin/gdrive files upload --parent ID --recursive /home/username/public_html
You can also back up individual files. The following cron job shows how to do this with a file named backup.tar.gz:
30 2 * * * /home/username/bin/gdrive files upload --parent ID /home/username/backup.tar.gz
To restore data from Google Drive to your A2 Hosting account, follow this step:
gdrive files download ID
To restore an entire directory, type the following command. Replace ID with the ID of the directory you want to restore:
gdrive files download --recursive ID
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.