Setting Up Google Drive Backups on Ubuntu with rclone
This tutorial will show you how to set up automated backups from Ubuntu Linux to Google Drive using rclone. You'll need Ubuntu Linux, a Google account with Google Drive, and terminal access with sudo privileges.
Installing rclone
If you haven't already installed rclone, open a terminal and run the following commands. The first updates your package list, and the second installs rclone from the Ubuntu repositories.
sudo apt update
sudo apt install rclone
You can verify the installation by checking the version number with rclone version
.
Why You Need Your Own Google OAuth Application
Google has restricted access to unverified third-party applications, which means rclone's default OAuth credentials no longer work for new users. When you try to authenticate with the default credentials, Google blocks access with an "Access blocked" error stating that rclone hasn't completed Google's verification process.
The solution is to create your own OAuth application in the Google Cloud Console. This gives you a private OAuth app that Google won't block, since you're authorizing your own application to access your own Google Drive. This is a one-time setup that takes about 10 minutes.
Creating Your Google OAuth Application
Start by going to the Google Cloud Console at console.cloud.google.com and signing in with your Google account. You'll need to create a new project for this application.
Setting Up the Project
Click the project dropdown at the top of the page and select "New Project". Give your project a name like "rclone-backup" and click Create. Wait a moment for Google to create the project, then make sure it's selected in the project dropdown.
Enabling the Google Drive API
From the left sidebar, navigate to "APIs & Services" and then "Library". Use the search box to find "Google Drive API". Click on it and press the Enable button. This allows your OAuth application to access Google Drive.
Configuring the OAuth Consent Screen
Before you can create OAuth credentials, you need to configure the consent screen. This is what users see when they authorize the application. Go to "APIs & Services" and then "OAuth consent screen".
Choose "External" as the user type and click Continue. You'll need to fill in some basic information about your application. For the app name, use something like "My rclone Backup". Enter your email address for both the user support email and developer contact information.
Click "Save and Continue" to move to the Scopes page. Click "Add or Remove Scopes" and search for the Google Drive scope. You need to add the scope https://www.googleapis.com/auth/drive
which gives full access to Google Drive. Select it, click Update, and then "Save and Continue".
On the Test users page, click "Add Users" and enter your Google email address. This allows you to use the application while it's in testing mode. Click Add, then "Save and Continue". You can review your settings and then click "Back to Dashboard".
Creating OAuth Credentials
Now you can create the actual credentials. Go to "APIs & Services" and then "Credentials". Click "Create Credentials" and choose "OAuth client ID".
For the application type, select "Desktop application". Give it a name like "rclone desktop client" and click "Create". A popup will appear showing your Client ID and Client Secret. Copy both of these values somewhere safe, or click "Download JSON" to save them. You'll need these in the next step.
Configuring rclone
Open your terminal and run rclone config
. This starts the interactive configuration process.
Type n
to create a new remote and press Enter. Give it a name like gdrive
. For the storage type, type drive
or find the number corresponding to Google Drive in the list and enter that number.
When prompted for client_id, paste the "Client ID" you copied from the Google Cloud Console. Press Enter, then paste your "Client Secret" when prompted. These custom credentials will allow you to bypass Google's access restrictions.
For the scope, choose option 1 for full access to all files. This gives rclone the ability to read and write any files in your Google Drive. Leave the root_folder_id
blank by pressing Enter. Also leave service_account_file
blank by pressing Enter.
When asked about advanced config, type n
for no. When asked "Use auto config?", type y
for yes. This will open a browser window where you'll log in to your Google account and grant permission to your OAuth application. You should see your application name and a prompt asking you to allow access to your Google Drive.
After granting permission, return to the terminal. When asked about configuring as a team drive, type n
for no unless you're using Google Workspace shared drives. Confirm the configuration looks correct by typing y
, then type q
to quit the configuration tool.
Testing Your Connection
Before proceeding, verify that rclone can connect to your Google Drive by running rclone lsd gdrive:
. This command lists the directories in your Google Drive. If you see your folders listed, the setup was successful.
Understanding Backup Methods
Rclone offers several commands for transferring files, and it's important to understand the differences before creating your backup script.
The sync
command makes the destination identical to the source. This means it will copy new and modified files to the destination, and it will also delete files from the destination that no longer exist in the source. This is ideal for maintaining an exact backup where you want the cloud to mirror your local files.
The copy
command only copies files from source to destination. It never deletes anything from the destination, even if files are removed from the source. This is useful if you want to keep historical versions of files in the cloud.
The bisync
command performs bidirectional synchronization, keeping both locations in sync. Changes made on either side are propagated to the other. This is more complex and requires careful use to avoid conflicts.
For most backup scenarios, sync
is the best choice because it maintains an exact copy of your current files in the cloud.
Creating a Backup Script
It's useful to create a script that handles your backups automatically. First, create a directory to store your scripts by running mkdir -p ~/scripts
.
Create a new file for your backup script with vim ~/scripts/backup-to-gdrive.sh
. Here's a basic backup script that you can customize for your needs:
#!/bin/bash
# Configuration
SOURCE_DIR="/home/$USER/Documents"
BACKUP_NAME="DocumentsBackup"
REMOTE_NAME="gdrive"
REMOTE_DIR="Backups/$BACKUP_NAME"
LOG_FILE="/home/$USER/logs/rclone-backup.log"
DATE=$(date '+%Y-%m-%d %H:%M:%S')
# Create log directory if it doesn't exist
mkdir -p "$(dirname "$LOG_FILE")"
# Log start
echo "[$DATE] Starting backup of $SOURCE_DIR to $REMOTE_NAME:$REMOTE_DIR" >> "$LOG_FILE"
# Run rclone sync
rclone sync "$SOURCE_DIR" "$REMOTE_NAME:$REMOTE_DIR" \
--progress \
--log-file="$LOG_FILE" \
--log-level INFO \
--exclude ".Trash-*/**" \
--exclude ".cache/**" \
--exclude "*.tmp"
# Check if backup was successful
if [ $? -eq 0 ]; then
echo "[$DATE] Backup completed successfully" >> "$LOG_FILE"
else
echo "[$DATE] Backup failed with errors" >> "$LOG_FILE"
fi
This script sets up some basic configuration variables at the top, creates a log directory if needed, and runs the sync command with logging enabled. It excludes common temporary files and cache directories that don't need to be backed up. After the sync completes, it checks whether the operation succeeded and logs the result.
Make the script executable by running chmod +x ~/scripts/backup-to-gdrive.sh
. You can now run your backup anytime by executing ~/scripts/backup-to-gdrive.sh
.
Backing Up Multiple Directories
If you want to backup multiple directories, you can extend your script to handle them all. Here's an example that backs up Documents, Pictures, and configuration files:
#!/bin/bash
REMOTE_NAME="gdrive"
LOG_FILE="/home/$USER/logs/rclone-backup.log"
DATE=$(date '+%Y-%m-%d %H:%M:%S')
mkdir -p "$(dirname "$LOG_FILE")"
echo "[$DATE] Starting backups" >> "$LOG_FILE"
# Backup Documents
rclone sync /home/$USER/Documents "$REMOTE_NAME:Backups/Documents" \
--log-file="$LOG_FILE" --log-level INFO
# Backup Pictures
rclone sync /home/$USER/Pictures "$REMOTE_NAME:Backups/Pictures" \
--log-file="$LOG_FILE" --log-level INFO
# Backup important config files
rclone sync /home/$USER/.config "$REMOTE_NAME:Backups/config" \
--log-file="$LOG_FILE" --log-level INFO \
--exclude "*/Cache/**" \
--exclude "*/cache/**"
echo "[$DATE] All backups completed" >> "$LOG_FILE"
Each directory is synced to a separate folder in your Google Drive under the Backups directory. This keeps your backups organized and makes it easier to restore specific types of files later.
Automating Backups with Cron
To run your backups automatically on a schedule, you can use the cron task scheduler. Edit your cron table by running crontab -e
. If this is your first time using crontab, you'll be asked to choose an editor.
Add a line to schedule your backup. The format is five time fields followed by the command to run. Here are some common schedules:
# Daily at 2 AM
0 2 * * * /home/yourusername/scripts/backup-to-gdrive.sh
# Every 6 hours
0 */6 * * * /home/yourusername/scripts/backup-to-gdrive.sh
# Every day at 3:30 PM
30 15 * * * /home/yourusername/scripts/backup-to-gdrive.sh
Replace yourusername
with your actual Ubuntu username. Save the file and exit the editor. Cron will now run your backup script on the schedule you specified.
Testing Before Running Real Backups
Before setting up automated backups, it's wise to test what rclone will do without actually transferring any files. The --dry-run
flag shows you exactly what would be copied, modified, or deleted without making any changes.
Run your script with a dry run by adding the flag to the rclone command temporarily, or run rclone directly from the command line like this:
rclone sync /home/$USER/Documents gdrive:Backups/Documents --dry-run --verbose
This will output a detailed list of actions that would be taken. Review this carefully to make sure it's doing what you expect. Pay special attention to any files that would be deleted.
Useful rclone Commands
There are several rclone commands that are helpful for managing your backups. To list files in your Google Drive, use rclone ls gdrive:
for all files or rclone lsd gdrive:
for just directories.
To check how much storage you're using, run rclone about gdrive:
. This shows your total storage, used space, and free space in Google Drive.
If you need to restore files from Google Drive back to your local system, you can reverse the sync direction:
rclone sync gdrive:Backups/Documents /home/$USER/Documents-Restored
Be very careful with this command. Using sync in the restore direction will make your local directory match the cloud, which means it could delete local files that aren't in the cloud backup.
To compare your local files with your cloud backup without transferring anything, use the check command:
rclone check /home/$USER/Documents gdrive:Backups/Documents
This reports any differences between the two locations without modifying either one.
Filtering Files
You often don't want to backup everything. Rclone provides powerful filtering options that you can add to your sync commands.
To exclude specific patterns, use the --exclude
flag. For example, --exclude "*.tmp"
skips all files ending in .tmp. You can use --exclude ".git/**"
to skip git repositories, or --exclude "node_modules/**"
to skip Node.js dependencies.
If you only want to backup specific file types, use --include
instead. For example, --include "*.jpg"
combined with --include "*.png"
will only backup image files. Note that when using include filters, you typically need to also add --exclude "*"
at the end to exclude everything that wasn't explicitly included.
You can also filter by file size or age. The flag --min-size 1M
only transfers files larger than 1 megabyte, while --max-age 30d
only transfers files modified in the last 30 days.
Optimizing Transfer Performance
By default, rclone transfers files one at a time. For better performance with many small files, you can increase the number of parallel transfers with --transfers 4
. This uploads four files simultaneously.
The --checkers 8
flag increases the number of files rclone checks simultaneously when determining what needs to be transferred. This can significantly speed up the initial scanning phase.
If you're backing up large files, increasing the buffer size with --buffer-size 16M
can improve transfer speeds by reducing the number of round trips to Google Drive.
If backups are consuming too much bandwidth and affecting your other internet usage, you can limit the transfer rate with --bwlimit 10M
to restrict uploads to 10 megabytes per second.
Monitoring Your Backups
It's important to verify that your backups are running successfully. You can check the log file directly with tail -f /home/$USER/logs/rclone-backup.log
to watch backups in real-time as they run.
To see the most recent backup events, use tail -n 20 /home/$USER/logs/rclone-backup.log | grep "Backup"
which shows the last 20 lines containing the word "Backup".
Create a simple monitoring script at ~/scripts/check-backup-status.sh
:
#!/bin/bash
LOG_FILE="/home/$USER/logs/rclone-backup.log"
echo "=== Recent Backup Events ==="
tail -n 20 "$LOG_FILE" | grep "Backup"
echo ""
echo "=== Google Drive Storage Usage ==="
rclone about gdrive:
echo ""
echo "=== Recently Backed Up Files ==="
rclone ls gdrive:Backups --max-depth 2 | tail -n 10
Make it executable with chmod +x ~/scripts/check-backup-status.sh
. Run this script occasionally to verify your backups are working correctly.
Troubleshooting Common Issues
If you get an error about failing to create a file system, first check your rclone configuration with rclone config show gdrive
. Make sure your client_id
and client_secret
are present. If they're missing or incorrect, run rclone config
again to reconfigure the remote.
Slow transfer speeds can have several causes. Your internet connection might be the bottleneck, especially for large files. Try adding --transfers 4
and --checkers 8
to speed things up. If uploads are interfering with other network activities, use --bwlimit
to limit the bandwidth rclone uses.
If files aren't syncing as expected, run the command with --dry-run
and --verbose
to see what rclone plans to do. Check that your exclude patterns aren't inadvertently blocking files you want to backup. Verify that you have read permission on the files you're trying to backup.
If rclone seems to hang or stop responding, it might be waiting for network operations to complete. The --timeout 30s
flag sets a timeout for individual operations. The --contimeout 60s
flag sets a timeout for initial connections.
Security Considerations
Your OAuth credentials provide access only to your own Google Drive account. The credentials are stored in ~/.config/rclone/rclone.conf
with permissions set to 600, meaning only your user account can read the file.
Keep your rclone.conf file secure. Don't share it with others or commit it to version control systems. If you ever need to revoke access, you can do so from your Google account settings under Security, then "Third-party apps with account access".
The client_id
and client_secret
from your OAuth application are not as sensitive as the tokens in rclone.conf
, but you should still keep them private. Anyone with these credentials could create their own rclone configuration to access their own Google Drive using your OAuth application.
If you're concerned about data privacy, remember that rclone transfers your files to Google's servers where they're stored according to Google's privacy policy. The files are encrypted in transit using HTTPS, but they're stored in Google Drive in a form that Google can technically access.
Maintaining Your Backup System
Once your backup system is running, check it periodically to ensure it's working correctly. Look at your log files every few weeks to verify backups are completing successfully. Log in to Google Drive occasionally and spot-check that your files are actually there.
Monitor your Google Drive storage space. If you're running low, you may need to clean up old files, purchase more storage, or adjust what you're backing up. You can check your storage usage with rclone about gdrive:
.
Keep rclone updated to get bug fixes and new features. Ubuntu's package manager will handle this when you run system updates, but you can also install the latest version directly from rclone.org if you need newer features.
As your needs change, update your backup script. You might want to backup additional directories, change your exclude patterns, or adjust the backup schedule. Remember to test changes with --dry-run
before running them for real.
Consider testing your restore process occasionally. The best backup system in the world is useless if you can't actually restore your files when you need them. Try restoring a few files to a temporary directory to verify the process works.
For more information and advanced features, consult the official rclone documentation at rclone.org.
Summary
This guide walked you through setting up automated backups from Ubuntu to Google Drive using rclone. You created your own Google OAuth application to bypass access restrictions, configured rclone to connect to your Google Drive, and built a backup script that can run automatically on a schedule. You learned about different sync methods, how to filter files, optimize transfers, and monitor your backups. With this system in place, your important files are regularly backed up to the cloud, protecting you against data loss from hardware failure, accidents, or other disasters. Remember to check your backups periodically and test the restore process to ensure everything works when you need it.
Featured Merch

Latest Posts
- Protecting Your Email Server: SASL Authentication and fail2ban Defense
- The Centenarian Decathlon: A Practical Guide to Thriving into Your 90s and Beyond
- The Pros and Cons of Cron Jobs
- Image Prompt Creator: Generate AI Prompts from Images
Featured Book

Subscribe to RSS Feed
This post was written by Ramiro Gómez (@yaph) and published on . Subscribe to the Geeksta RSS feed to be informed about new posts.
Tags: rclone guide backup google drive linux
Disclosure: External links on this website may contain affiliate IDs, which means that I earn a commission if you make a purchase using these links. This allows me to offer hopefully valuable content for free while keeping this website sustainable. For more information, please see the disclosure section on the about page.