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.
The gdrive program enables you to access and manipulate Google Drive files and directories from the command line.
To install and configure the gdrive program for your account, 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:
You should receive output that resembles the following text:
gdrive 3.9.0 Commit: unknown Rust: 1.68.0 Arch: x86_64 OS: linux
After you have installed gdrive you are ready to configure it to access your Google account. To do this, follow these steps:
Click the clipboard icon to copy the verification code:
At the command prompt, paste the verification code that you obtained in step 7, and then press Enter. You should receive the following message (the actual names and amounts will differ):
User: Kelly Koe, [email protected] Used: 181.6 MB Free: 32.1 GB Total: 32.2 GB Max upload size: 5.2 TB
gdrive is now configured to use your Google Drive account.
To list your Google Drive files and directories, type the following command:
This command displays the ID number, name, type, size, and creation date for all of the files and directories in your Google Drive 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 mkdir backups
To verify that the directory was created successfully, type the following command:
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 command demonstrates how to back up the entire public_html directory to the Google Drive backups directory daily at 2:30 AM. You should 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 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 upload --parent ID /home/username/backup.tar.gz
To restore data from Google Drive to your A2 Hosting account, follow this step:
gdrive download ID
To restore an entire directory, type the following command. Replace ID with the ID of the directory you want to restore:
gdrive download --recursive ID
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.