Using Google Drive to Backup and Restore Data in Ruachost
Ruachost allows you to configure Google Drive as an offsite backup destination for your hosting account. This ensures your website files and databases are securely stored in the cloud and can be restored if needed.
Why Use Google Drive for Backups?
Section titled “Why Use Google Drive for Backups?”- Offsite protection: Keeps your data safe even if your hosting server is compromised.
- Easy access: Manage and download backups directly from your Google Drive account.
- Automation: Schedule backups to run automatically via cron jobs.
- Scalability: Use your existing Google Drive storage without additional infrastructure.
Steps to Configure Google Drive Backups
Section titled “Steps to Configure Google Drive Backups”Step 1: Create Google API Credentials
Section titled “Step 1: Create Google API Credentials”- Log in to the Google Cloud Console.
- Create a new project (e.g. ruachost-backup).
- Enable the Google Drive API.
- Configure the OAuth consent screen.
- Create OAuth client credentials (Desktop app).
- Copy the Client ID and Client Secret (you’ll need these later.)
Step 2: Install the gdrive Utility
Section titled “Step 2: Install the gdrive Utility”The gdrive command-line tool is used to interact with Google Drive.
-
On your local computer:
-
Download the latest release from GitHub (gdrive).
-
Extract the file and verify installation by running:
Terminal window ./gdrive version
-
-
On your Ruachost hosting account:
-
Upload the
gdrivebinary to your account (e.g., into~/bin/). -
Make it executable:
Terminal window chmod +x ~/bin/gdrive
-
Step 3: Authenticate Google Drive
Section titled “Step 3: Authenticate Google Drive”-
Run:
Terminal window gdrive account add -
Enter your Client ID and Client Secret.
-
Open the provided URL in your browser, log in to Google, and approve access.
-
Export the configuration and upload it to your Ruachost account if needed.
Step 4: Create a Backup Directory in Google Drive
Section titled “Step 4: Create a Backup Directory in Google Drive”gdrive files mkdir backups- Note the directory ID returned, you’ll use this in your cron jobs.
Step 5: Automate Backups with Cron
Section titled “Step 5: Automate Backups with Cron”Set up a cron job in cPanel or via SSH to back up your site automatically.
Example: Back up your public_html folder daily at 2:30 AM:
30 2 * * * /home/username/bin/gdrive files upload --parent DIRECTORY_ID --recursive /home/username/public_htmlExample: Back up a single archive file:
30 2 * * * /home/username/bin/gdrive files upload --parent DIRECTORY_ID /home/username/backup.tar.gzStep 6: Restoring Data from Google Drive
Section titled “Step 6: Restoring Data from Google Drive”-
To restore a single file:
gdrive files download FILE_ID -
To restore an entire directory:
gdrive files download --recursive DIRECTORY_ID