How to Automatically Backup VPS to OneDrive with Rclone

How to Automatically Backup VPS to OneDrive with Rclone

Backing up your VPS to OneDrive is a practical way to store 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 archive that can be downloaded from OneDrive.

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

In this tutorial, we will use the folder /var/backups/wpgan to store website archives and database exports. If you use a control panel and have already set up automatic backups, you can simply use the existing backup folder.

Prerequisites for Backing Up VPS to OneDrive

  • VPS with a Linux operating system
  • SSH access and sudo permissions to install packages
  • Microsoft account with sufficient OneDrive storage
  • Computer with a browser and rclone to log in to OneDrive
  • Backup folder readable by the user who will run the cron job

How to Automatically Backup VPS to OneDrive 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 the 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 rclone

After installing rclone, check the location of the binary and its configuration file. Both paths will be used later 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. Check the binary and configuration file locations for that same account.

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

2. Add OneDrive to Rclone

Now you can start adding OneDrive to rclone. In the VPS terminal, run the following command.

rclone config

Type n to create a new remote, then enter a name, for example onedrive-wpgan. In the Storagesection, type onedrive to select Microsoft OneDrive.

When asked to fill in the Client ID and Client Secret, press Enter to use the default rclone settings. If the Regionoption appears, use global for a standard OneDrive account. After that, select n when asked if you want to change advanced settings.

Cara Backup VPS ke OneDrive Otomatis dengan Rclone - WPGan.com - 2

3. Log in to OneDrive from Your Computer

When rclone offers to open a browser (Use auto config), select n because the configuration is running on the VPS. Rclone will display a command rclone authorize that needs to be run on a computer with a browser. Copy the full command, including the additional arguments displayed. If possible, use the same version of rclone on both the VPS and the computer.

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

Run that command on your computer, log in with the Microsoft account you will use to store backups, and grant access permissions. Once the login is successful, copy the token that appears in the computer terminal and paste it into the prompt config_token on the VPS. Keep this token private, as it is used to access your OneDrive account.

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

4. Select Drive and Check OneDrive Connection

After the token is pasted into the prompt config_token, rclone will ask for the connection type. Type 1 or onedrive at the prompt config_type to select OneDrive Personal or Business.

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

Rclone will then display a list of available drives. At the prompt config_driveid, select the option OneDrive (personal), which is number 2 in this example. If the order is different for your account, select the number corresponding to OneDrive (personal). Check your selection before pressing Enter, as the default drive may vary.

If you are subsequently asked Found drive "root" of type "personal" and “Keep this "onedrive-wpgan" remote?“, select the option y.

After that, confirm the selected drive, save the remote, and exit the configuration menu. Run the following command to check the connection.

rclone lsd onedrive-wpgan:

If the command finishes without errors, you can proceed to the upload process. The folder list may be empty if your OneDrive does not have any folders yet.

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

5. Prepare the Backup Folder on the VPS

Ensure the folder /var/backups/wpgan already contains backup files. For WordPress websites, this can include website file archives and database exports in .sql or .sql.gz.

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

format. Use a name that includes the date, for example website-2026-11-26.tar.gz, if you want to keep multiple backup versions. Archives with the same name may be overwritten by subsequent uploads when their contents change.

6. Try Uploading a Backup Manually

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

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

Rclone will create the destination folder if it does not exist. The command copy will skip identical files and keep copies in OneDrive even if the local files are deleted from the VPS.

Cara Backup VPS ke OneDrive Otomatis dengan Rclone - WPGan.com - 6

After the upload is complete, open OneDrive and check the folder Backup-VPS → wpgan. You can also view the contents from the terminal.

rclone lsf onedrive-wpgan:Backup-VPS/wpgan

7. Schedule Backup Uploads with Cron

Once the manual upload is 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 onedrive-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 from command -v rclone and rclone config file from the first step.

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

Set the upload time for after the backup process on the VPS is finished. For example, if your 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 OneDrive

If you want to download a backup file from OneDrive to your VPS, check the file name with rclone lsf, then run the following command.

mkdir -p /var/backups/restore
rclone copyto onedrive-wpgan:Backup-VPS/wpgan/website-2026-11-26.tar.gz /var/backups/restore/website-2026-11-26.tar.gz --progress

Replace website-2026-11-26.tar.gz with the name of the file you want to download. If the remote name on the VPS is different, replace onedrive-wpgan: with the name of the remote you created. You can see a list of remote names with rclone listremotes.

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

Once finished, open the archive to ensure the file is readable. If your website and database backups are stored separately, download both.

FAQ: How to Backup VPS to OneDrive 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 your 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 in the source.

Why hasn't my new website appeared in OneDrive?

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 your control panel. If the archive is already there, check the source path in cron and look at rclone-backup.log to see if there are any errors.

How do I reconnect a configured OneDrive account?

Run the following command with the user running the cron job, then follow the login process as you did during the initial setup. If cron uses --config with a specific path, use the same path when reconnecting the remote.

rclone config reconnect onedrive-wpgan:

Will old backups in OneDrive be deleted automatically?

With rclone copy, dated archives that have been uploaded will remain stored even if the local files have been deleted. If backups are created daily, check your OneDrive capacity periodically because the number of archives will continue to grow.

What if a “Need admin approval” message appears when logging into OneDrive?

If you are using a work or school account, your organization may restrict which applications can access OneDrive. Ask your Microsoft 365 admin to check if rclone access can be approved. After receiving approval, repeat the login process from the third step.

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...