In today’s digital age, safeguarding your data is more crucial than ever. With the increasing reliance on cloud storage, it’s essential to have a robust backup strategy in place. This blog post will guide you through automating your cloud backups (like Onedrive in this example) using rclone
and Duplicati
on a Linux system (in my case Ubuntu 24.04.1 LTS).
Why rclone and Duplicati?
- rclone: A versatile command-line tool (inspired by rsync) that supports various cloud storage providers, including OneDrive. It allows you to sync, copy, and mount cloud storage as if it were a local filesystem.
- Duplicati: An open-source backup solution that offers incremental backups, encryption, and scheduling. It’s designed to work efficiently with cloud storage, making it an ideal choice for automated backups.
We’ll use rclone
to mount your OneDrive folder as a local directory seamlessly. This setup allows Duplicati
to perform smart incremental backups, ensuring your data is securely backed up without unnecessary duplication. In this guide, I’ll walk you through the steps to set up rclone
and Duplicati
, making sure your cloud storage is backed up efficiently and securely. Let’s get started!
Install rclone
This command downloads and runs the installation script for rclone
, making it easy to install on most Unix-like systems, including Linux and macOS. For Windows, you can download the executable from the rclone website.
run apt install rclone
apt install rclone
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
rclone
0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.
Need to get 21.4 MB of archives.
After this operation, 65.9 MB of additional disk space will be used.
Get:1 http://packages.azlux.fr/debian bookworm/main arm64 rclone arm64 1.68.2 [21.4 MB]
Fetched 21.4 MB in 2s (10.2 MB/s)
Selecting previously unselected package rclone.
(Reading database ... 133411 files and directories currently installed.)
Preparing to unpack .../rclone_1.68.2_arm64.deb ...
Unpacking rclone (1.68.2) ...
Setting up rclone (1.68.2) ...
Processing triggers for man-db (2.12.0-4build2) ...
Install Duplicati
The install-process of Duplicati is already explained here.
Onedrive homework
By default, rclone
uses a shared Client ID and Key when communicating with OneDrive, unless a custom client_id
is specified in the configuration. This means that all rclone
users share the same default Client ID for their requests. This is everything but not optimal, also throttling usually occurs.
Recommended step: Create unique Client ID for Onedrive personal
click New registration
on https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade and follow the steps outlined at the rclone page.
My screenshots for this step are attached (just for your reference, please zoom in to make the file readable in your browser. ).
Setup rclone
This section guides you through the steps to configure rclone
to mount your OneDrive folder to use this mount point as the source for Duplicati
backups.
run rclone config
and answer the questions
Example output (Ubuntu 24.04)
rclone config
2024/12/17 11:06:25 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
Enter name for new remote.
name> onedrive
Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
35 / Microsoft OneDrive
\ (onedrive)
Storage> 35
Option client_id.
OAuth Client Id.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_id>
Option client_id.
OAuth Client Id.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_id>
Option client_secret.
OAuth Client Secret.
Leave blank normally.
Enter a value. Press Enter to leave empty.
client_secret>
Option region.
Choose national cloud region for OneDrive.
Choose a number from below, or type in your own value of type string.
Press Enter for the default (global).
1 / Microsoft Cloud Global
\ (global)
2 / Microsoft Cloud for US Government
\ (us)
3 / Microsoft Cloud Germany
\ (de)
4 / Azure and Office 365 operated by Vnet Group in China
\ (cn)
region> 1
Edit advanced config?
y) Yes
n) No (default)
y/n>n
Use web browser to automatically authenticate rclone with remote?
* Say Y if the machine running rclone has a web browser you can use
* Say N if running rclone on a (remote) machine without web browser access
If not sure try Y. If Y failed, try N.
y) Yes (default)
n) No
y/n> n
Option config_token.
For this to work, you will need rclone available on a machine that has
a web browser available.
For more help and alternate methods see: https://rclone.org/remote_setup/
Execute the following on the machine with the web browser (same rclone
version recommended):
rclone authorize "onedrive"
Then paste the result.
Enter a value.
config_token>
for Use web browser to automatically authenticate rclone with remote?:
Choose “Yes” if your host supports a GUI.
In my case I have to answer this question with no and have to jump on an GUI-equipped host running the same clone-version to generate the needed one drive-token with the command: rclone authorize "onedrive"
{"access_token":"EwCIA8blablaadv!0","expiry":"202blabla.927609745Z"}
Option config_type.
Type of connection
Choose a number from below, or type in an existing value of type string.
Press Enter for the default (onedrive).
1 / OneDrive Personal or Business
\ (onedrive)
2 / Root Sharepoint site
\ (sharepoint)
/ Sharepoint site name or URL
3 | E.g. mysite or https://contoso.sharepoint.com/sites/mysite
\ (url)
4 / Search for a Sharepoint site
\ (search)
5 / Type in driveID (advanced)
\ (driveid)
6 / Type in SiteID (advanced)
\ (siteid)
/ Sharepoint server-relative path (advanced)
7 | E.g. /teams/hr
\ (path)
config_type> 1
vblabla+g0","expiry":"202blabla27609745Z"}
Option config_type.
Type of connection
Choose a number from below, or type in an existing value of type string.
Press Enter for the default (onedrive).
1 / OneDrive Personal or Business
\ (onedrive)
2 / Root Sharepoint site
\ (sharepoint)
/ Sharepoint site name or URL
3 | E.g. mysite or https://contoso.sharepoint.com/sites/mysite
\ (url)
4 / Search for a Sharepoint site
\ (search)
5 / Type in driveID (advanced)
\ (driveid)
6 / Type in SiteID (advanced)
\ (siteid)
/ Sharepoint server-relative path (advanced)
7 | E.g. /teams/hr
\ (path)
config_type> 1
Option config_driveid.
Select drive you want to use
Choose a number from below, or type in your own value of type string.
Press Enter for the default (7bla49295c6fb0).
1 / (personal)
\ (7blae49295c6fb0)
config_driveid>
Drive OK?
Found drive "root" of type "personal"
URL: https://onedrive.live.com/?cid=07bla49295c6fb0
y) Yes (default)
n) No
y/n>
Configuration complete.
Options:
- type: onedrive
- token: {"access_token":"EwCIblabla==","token_type":"Bearer","refresh_token":"K.Abla1.0.U.-CsblaFy55aAHgafDLr5t0","expiry":"202blabla609745Z"}
- drive_id: 79blabla95c6fb0
- drive_type: personal
Keep this "onedrive" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d>
Current remotes:
Name Type
==== ====
onedrive onedrive
Now we can mount the onedrive-storage-folder as a mount-point.
In this example I use /mnt/onedrive as the mount-point (the folder /mnt/onedrive must be present prior executing the mount command):
rclone mount onedrive:/ /mnt/onedrive
Let’s create an rclone-service to mount the one drive-folder at startup:
vi /etc/systemd/system/rclonemount.service
[Unit]
Description=rclonemount
AssertPathIsDirectory=/mnt/onedrive
After=network-online.target
[Service]
Type=simple
ExecStart=/usr/bin/rclone mount \
--config=/root/.config/rclone/rclone.conf \
--vfs-cache-mode writes \
onedrive: /mnt/onedrive
ExecStop=/bin/fusermount -u /mnt/onedrive
Restart=always
RestartSec=10
[Install]
WantedBy=default.target
Start and test the created rclonemount.service:
systemctl start rclonemount
┌──$(root㉿raspi24)-[/]
└─# systemctl status rclonemount
● rclonemount.service - rclonemount
Loaded: loaded (/etc/systemd/system/rclonemount.service; enabled; preset: enabled)
Active: active (running) since Tue 2024-12-17 16:33:29 CET; 1 week 5 days ago
Main PID: 1039 (rclone)
Tasks: 12 (limit: 8674)
Memory: 68.4M (peak: 131.5M)
CPU: 15min 9.054s
CGroup: /system.slice/rclonemount.service
└─1039 /usr/bin/rclone mount --config=/root/.config/rclone/rclone.conf --vfs-cache-mode writes onedrive: /mnt/onedrive
run rclonemount.service at startup:
systemctl enable rclonemount
┌──$(root㉿raspi24)-[/]
└─# systemctl enable rclonemount
Created symlink /etc/systemd/system/default.target.wants/rclonemount.service → /etc/systemd/system/rclonemount.service.
With Duplicati we can create now a new Backup-Job using the source directory /mnt/onedrive, or any specific subfolder like /mnt/onedrive/important_data.
Onedrive can now be backed up fully automatically with a smart backup solution 🙂
As we wrap up our journey with rclone, it’s clear that this powerful tool can significantly streamline your data management tasks. Whether you’re syncing files across multiple cloud services, automating backups, or simply exploring new ways to enhance your workflow, rclone offers a versatile and reliable solution.
Remember, the key to mastering rclone—or any tool—is practice and experimentation. Don’t hesitate to dive into the documentation, explore the various commands, and tailor rclone to fit your unique needs. The possibilities are vast, and the more you experiment, the more you’ll discover the true potential of this remarkable tool.