How to Automatically Backup VPS to Google Drive with Rclone

How to Automatically Backup VPS to Google Drive with Rclone

Backing up your VPS to Google Drive is a practical way to keep copies of your website files and databases off-server. If your VPS files are ever deleted or you need to migrate servers, you will still have a backup copy that can be downloaded from Google Drive.

TL;DR: To automatically backup your VPS to Google Drive, install rclone, connect your Google Drive account via rclone config, then try uploading the backup folder with rclone copy. Once the files are successfully in Google Drive, schedule the upload command using cron.

In this tutorial, we will use the folder /var/backups/wpgan to store website archives and database exports. If your control panel already creates backups automatically, you can use that existing backup folder directly.

Prerequisites for Backing Up VPS to Google Drive

  • VPS with a Linux operating system
  • SSH access and sudo permissions to install packages if needed
  • Google Drive account with sufficient storage space
  • Computer with a browser and rclone to log in to Google Drive
  • Backup folder that can be read by the user running the cron job

How to Automatically Backup VPS to Google Drive with Rclone

The following installation example uses Ubuntu or Debian. If you are using a different distribution, adjust the installation steps accordingly.

1. Log in to VPS and Install Rclone

First, log in to your VPS via SSH. If you are using Ubuntu or Debian, install rclone with the following command.

sudo apt updatesudo apt install rclonerclone version

Once the rclone version appears, check the location of the binary and its configuration file. Both of these paths will be used when creating the cron job.

command -v rclonerclone config file

Run the rclone configuration and create the cron job using the same user. For example, if the backup is scheduled via sudo crontab -e, perform the rclone configuration as root as well.

Cara Backup VPS ke Google Drive Otomatis dengan Rclone - WPGan.com - 1

2. Create an OAuth Client for Google Drive

Open Google Cloud Console, create or select a project, then enable Google Drive API. After that, open Google Auth Platform, complete the application settings, and create an OAuth client with the type Desktop app. Save the Client ID and Client Secret that appear.

Cara Backup VPS ke Google Drive Otomatis dengan Rclone - WPGan.com - 2-1

If you are using a personal Google account, select External under the Audiencesection. For routine backups, change the application status to In production via Publish app. If it is still in Testingstatus, the Google Drive access granted to rclone may expire after seven days. The rclone guide also includes steps to complete the Data Access and Branding settings if requested.

Cara Backup VPS ke Google Drive Otomatis dengan Rclone - WPGan.com - 2-2
Cara Backup VPS ke Google Drive Otomatis dengan Rclone - WPGan.com - 2-3

3. Add Google Drive in Rclone

Return to the VPS terminal and run the following command.

rclone config

Select New remote by typing n, then enter a remote name, for example gdrive-wpgan. In the storage type section, type 18 to select Google Drive. Enter the Client ID and Client Secret you created.

Cara Backup VPS ke Google Drive Otomatis dengan Rclone - WPGan.com - 3-1

In the Scopesection, select drive.file (3) if you want rclone to only access files it created itself. This tutorial uses a new destination folder that will be created during the first upload. For the service account option, leave it blank, then select n when asked if you want to change advanced settings.

Cara Backup VPS ke Google Drive Otomatis dengan Rclone - WPGan.com - 3-2

4. Log in to Google Drive from Your Computer

When rclone asks if you want to open a browser to log in, select n because the configuration process is running on the VPS. Rclone will display a command rclone authorize that you need to run on a computer with a browser. Copy the full command, including the additional arguments displayed.

Cara Backup VPS ke Google Drive Otomatis dengan Rclone - WPGan.com - 4-1

After logging in and granting access, copy the token that appears in the computer terminal, then paste it into the prompt config_token on the VPS. If a question appears about Shared Drive, select n if your backup destination is My Drive. Save the remote, then check the connection.

rclone lsd gdrive-wpgan:

If the command finishes without errors, you can proceed to the upload process. The folder list might be empty if you use the drive.file permission and rclone has not created any folders yet.

Cara Backup VPS ke Google Drive Otomatis dengan Rclone - WPGan.com - 4-2

5. Prepare the Backup Folder on the VPS

Make sure the folder /var/backups/wpgan already contains backup files. For WordPress websites, the contents can be website file archives and database exports in .sql or .sql.gz.

Cara Backup VPS ke Google Drive Otomatis dengan Rclone - WPGan.com - 5

format. If backups are created via a control panel, check the storage location and use that path in the rclone command. If there is a new website on the VPS, ensure it is included in the backup schedule in the panel so its archive appears in the source folder.

Use an archive name that includes the date, for example website-2026-11-25.tar.gz, if you want to keep multiple backup versions. Files with the same name can be updated by rclone copy when their contents change.

6. Test Uploading Backups Manually

Before creating an automatic schedule, try uploading the contents of the backup folder to Google Drive with the following command. Replace /var/backups/wpgan if your backup folder is in a different location.

rclone copy /var/backups/wpgan gdrive-wpgan:Backup-VPS/wpgan --progress

Rclone will create the destination folder if it does not exist. The command copy will skip files that are already the same and will keep files in Google Drive even if their copies have been deleted from the VPS.

Cara Backup VPS ke Google Drive Otomatis dengan Rclone - WPGan.com - 6-1

Once finished, open Google Drive and check the folder Backup-VPS → website. You can also view the contents from the terminal.

rclone lsf gdrive-wpgan:Backup-VPS/wpgan
Cara Backup VPS ke Google Drive Otomatis dengan Rclone - WPGan.com - 6-2

7. Schedule Backup Uploads with Cron

If the manual upload was successful, open the crontab for the user previously used to run rclone.

crontab -e

Add the following line to run the upload every day at 5:00 AM according to the time zone used by cron on the VPS.

0 5 * * * /usr/bin/rclone --config /home/ubuntu/.config/rclone/rclone.conf copy /var/backups/wpgan gdrive-wpgan:Backup-VPS/wpgan --log-level INFO >> "$HOME/rclone-backup.log" 2>&1

Path /usr/bin/rclone and /home/ubuntu/.config/rclone/rclone.conf are examples. Replace both with the results of command -v rclone and rclone config file from the first step.

Cara Backup VPS ke Google Drive Otomatis dengan Rclone - WPGan.com - 7

Set the upload time for after the backup process on the VPS is finished. For example, if the control panel starts creating backups at 3:00 AM and usually finishes before 4:00 AM, you can schedule the upload for 5:00 AM.

8. Download Backups from Google Drive

If you want to download a backup file directly from Google Drive to your VPS, run the following command.

mkdir -p /var/backups/restore
rclone copyto gdrive-wpgan:Backup-VPS/wpgan/wordpress-backup-11262026.tar.gz /var/backups/restore/wordpress-backup-11262026.tar.gz --progress

Replace wordpress-backup-11262026.tar.gz with the name of the file you want to download and adjust remote: with the remote name in your rclone configuration. Once finished, open the archive to ensure the backup file is readable. If website and database backups are stored separately, download both.

Cara Backup VPS ke Google Drive Otomatis dengan Rclone - WPGan.com - 8

FAQ: How to Backup VPS to Google Drive with Rclone

Can rclone back up databases directly?

Rclone uploads files that are already available on the VPS. To back up a database, create an export first via the control panel or tools like mysqldump or mariadb-dump, then save the result to the backup folder that will be uploaded.

What is the difference between rclone copy and rclone sync for backups?

rclone copy copies new or changed files without deleting files at the destination. Meanwhile, rclone sync adjusts the contents of the destination folder to match the source folder, including deleting files at the destination if they no longer exist at the source.

Why hasn't my new website appeared in Google Drive?

First, check if the new website archive has appeared in the backup folder read by rclone. If the archive is not there, check the backup settings in the control panel. If the archive is already there, check the source path in cron and look at the upload log to see if there are any errors.

How do I reconnect a Google Drive that has already been configured?

Run rclone config reconnect gdrive-wpgan: with the user running the cron job, then follow the login process as you did during the initial setup. Replace gdrive with the remote name already used on the VPS.

Will old backups in Google Drive be deleted automatically?

With the command rclone copy in this tutorial, dated archives that have been uploaded will remain stored until you delete them. If backups are created daily, check your Google Drive capacity periodically because the number of archives will continue to grow.

How do I fix Error 403 access_denied when connecting rclone to Google Drive?

If a message appears saying Access blocked stating the application is still in the testing phase, open Google Cloud Console and select the OAuth project you are using for rclone. Go to Google Auth Platform → Audience → Test users, click Add users, then enter the email of the Google account that will be used to store backups. After saving, rerun the command rclone authorize and log in with that account.

If rclone is used for automatic backups, change the application status to In production via Audience → Publish app, then repeat the authorization. As long as the application is still in Testingstatus, the token for Google Drive access can expire after seven days, which may cause subsequent uploads via cron to fail.

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...