DEV Community

loading...

RClone in a Docker to backup OneDrive locally

Jacob Korsgaard
I make video game tools in Denmark
・2 min read

Today I'm trying to setup my Unraid server to take a daily backup of the contents of my OneDrive folder. That's in case of catastrophic failure on Microsoft's side, or more likely, I mess up and nuke my OneDrive folder for whatever reason. It's also just nice to have the data available locally.

To accomplish this task I'm using RClone and I'm using it from a Docker container, primarily to continue on my learning journey with Docker. It's also nice that I could test things out on my Windows PC and easily move the setup to my Unraid server.

The RClone image I used is rclone/rclone:latest. That said, in order to actually get started with RClone you need to configure it first, that is give it access to whatever cloud service you want to access.

To do this I downloaded the Windows binary instead, because RClone has a simple interactive flow you can use to create a configuration file. See instructions here.

After running the configuration I had an rclone.conf file ready to go. I deployed this to the Unraid server and set about defining the command-line to use to backup my Unraid settings.

I went with a sync command parameterized with --backup-dir. Then I set the command to run using the "Community Applications User Scripts" plugin on Unraid (which is basically just an easy way to setup cron jobs from the Unraid WebUI)

The final bash script looks something like this:

#!/bin/bash
NOW=$(date +"%Y-%m-%d")
docker run --rm \
  --volume /mnt/user/appdata/rclone:/config/rclone \
  --volume /mnt/user/onedrive:/data \
  rclone/rclone sync onedrive: /data/root \
  --backup-dir /data/backup/$NOW
Enter fullscreen mode Exit fullscreen mode

First we create a date string for the backup folder. The backup folder is used whenever a file is deleted by the sync operation. Note: It's likely I'll want to run a deduplication script after syncing so the backup folder doesn't end up full of files that I already backed up.

Then we mount in the config folder for rclone as well as the target folder to copy the files to.

Finally, we run the RClone command with the root OneDrive folder as source onedrive: and the mounted folder as the target /data/root.

The onedrive: label is the one I created for my connection to OneDrive during configuration of RClone.

The one remaining niggle with the result is that the files created are all read/write only by root and read-only by everyone else. For my purpose, that's fine.

Discussion (0)