LW IT Solutions
« Blog Overview /IT & Networks / How to Set Up Rclone with Google...
This post in other languages:

How to Set Up Rclone with Google Drive on a Headless Server (The Right Way)

Backing up your remote server (like a Raspberry Pi) directly to Google Drive is a brilliant way to ensure data safety. The tool for the job is Rclone – the “Swiss Army knife” of cloud storage. However, setting it up on a “headless” server (a machine without a graphical interface or web browser) can be tricky, especially when dealing with Google’s authentication.

In this guide, we will walk you through the bulletproof method: creating your own Google Cloud Platform (GCP) project to avoid rate limits, authorizing on your local machine, and moving the configuration to your server.

Phase 1: Creating Your GCP Project (Avoiding Rate Limits)

Using Rclone’s default Google Drive client ID means sharing bandwidth with thousands of other users, leading to throttling. Here is how to create your own:

  1. Create a Project: Go to the Google Cloud Console, click the project dropdown, and select New Project. Name it something like “Rclone Backup”.
  2. Enable the API: Search for Google Drive API in the top search bar and click Enable.
  3. Configure OAuth Consent Screen:
    • Go to APIs & Services > OAuth consent screen.
    • Choose External user type.
    • Fill in the mandatory fields (App name, email addresses).
    • Under “Scopes”, add .../auth/drive to give Rclone full access to manage files.
    • Under “Test users”, add your own Google account email.
  4. Generate Credentials:
    • Go to the Credentials tab.
    • Click Create Credentials > OAuth client ID.
    • Crucial step: Choose Desktop app as the application type. This prevents issues with redirect URLs later.
    • Click Create. Copy your Client ID and Client Secret.

Phase 2: Local Authorization

Since your server doesn’t have a web browser, we will generate the access token on your main computer (Windows/Mac/Linux).

  1. Install Rclone on your local computer.
  2. Open a terminal and type rclone config.
  3. Press n for a new remote and name it (e.g., gdrive).
  4. Choose drive as the storage type.
  5. Paste your Client ID and Client Secret when prompted.
  6. When asked Use auto config?, type y (Yes).
  7. Your browser will open. Log in and grant permission.
  8. Back in the terminal, you will see a block of JSON code containing your token. Copy this entire token block.

Phase 3: Server Configuration

Now, let’s move to your headless server (via SSH).

  1. Install Rclone on your server (sudo apt install rclone).
  2. Run rclone config.
  3. Create a new remote (n), name it exactly as you did locally (gdrive), choose drive, and paste your Client ID and Secret.
  4. When asked Use auto config?, type n (No).
  5. When prompted for the result/token, paste the JSON block you copied from your local machine.
  6. Save and exit. Test it by typing rclone lsd gdrive:. You should see your Google Drive folders!

Phase 4: Automating Backups

Now that Rclone is authorized, let’s set up an automated backup script. Create a file named backup.sh:

Bash

#!/bin/bash
BACKUP_DIR="/path/to/local/backup"
DATE=$(date +%Y-%m-%d)
REMOTE="gdrive:ServerBackups"

# Your backup commands here (e.g., mysqldump, tar)
tar -czf "$BACKUP_DIR/data_$DATE.tar.gz" /var/www/html

# Copy to Google Drive (Rclone creates the folder automatically)
rclone copy "$BACKUP_DIR/data_$DATE.tar.gz" "$REMOTE"

# Keep only the last 7 days of backups on Google Drive
rclone delete "$REMOTE" --min-age 7d

Make the script executable (chmod +x backup.sh) and add it to your cron jobs (crontab -e) to run nightly. Your headless server is now securely backed up to the cloud!

Lukas Wojcik

Lukas Wojcik

Systems architect and technology enthusiast specializing in scalable tracking solutions, GMP Stack (GA4 & GTM), and robust backend architectures. Advocate for clean code and privacy-first design.

Get in Touch

Briefly describe your project or inquiry for a tailored response. This site is protected by reCAPTCHA.

Leave a Reply

Your email address will not be published. Required fields are marked *

ALL ARTICLES & CATEGORIES

Data Privacy

Digital Analytics

Digital Marketing

IT & Networks

Raspberry PI

Smart Home

Tutorials

Tutorials

Tutorials

Tutorials

Tutorials

Uncategorized

Web Development

Wordpress Hacks

Home Sitemap