Back to wiki
setting up rclone and crontab for automated cloud storage

Setting Up Rclone And Crontab For Automated Cloud Storage

Name: setting-up-rclone-and-crontab-for-automated-cloud-storage

Last reviewed by: Clipper, April 2026


Setting up Rclone and Crontab for automated cloud storage

This guide walks you through setting up Rclone combined with Crontab to achieve automated, reliable cloud storage for your media library on a Bytesized Hosting server. By creating an encrypted Google Drive remote (gcrypt) and merging it with a local temporary directory using an Rclone union remote, the setup provides a single virtual mount point (~/mnt/media_merge) that appears seamless to Sonarr, Radarr, and Plex. New downloads are first stored locally for speed and stability, then automatically moved to the encrypted cloud storage at scheduled intervals via a Crontab-triggered script. This approach minimizes API calls, prevents mount-related freezes, enables instant Plex library updates through filesystem notifications, and keeps maintenance simple and robust.


Table of contents

  1. About this guide
  2. Directories
  3. Setting up Rclone
  4. Setting up scripts
  5. Setting up Crontab
  6. Final steps

About this guide

Precursor

This guide will take you through a specific setup. It's not the only perfect setup that everyone should use, but it has proven to be easy to maintain and to run smoothly for a lot of people so far.

⚠️ IMPORTANT: While Bytesized Hosting provides these tools for their members, they don't provide any official support for rclone, plexdrive or similar remote mount setups. If something goes wrong, you're on your own. Use at your own risk.


Updates

04/01/2022

Mergerfs is no longer used in this guide and has been replaced with an Rclone Union remote, which serves the same purpose but without the added complexity of Mergerfs. Thanks to "@Error Loading Username" on Discord for letting me know about it.

The archived Mergerfs version of this page can be found here.


Rclone

Rclone is a tool that allows you to mount remote filesystems. It will be used for attaching Google Drive to your box. In this guide we will be using an Rclone crypt remote for remote file encryption (optional), and a union remote to merge the remote and local directories into one virtual directory and control the flow of data between them. This will be used to:

  • Expose a single access point to your media files for your apps (Sonarr, Plex, etc.), effectively hiding the difference between local and remote.
  • Employ a local, temporary file storage that ensures a low amount of API hits and no stuck apps because of a frozen mount.
  • Allow Plex to receive filesystem notifications so that it is immediately and automatically aware of new or changed media files.

We will not be using a cache remote.

Note: Rclone updates periodically and the numbers on the storage remote type list change. As you use this guide, reference the name of the remote type you need — the number may not match. i.e. look for Google Drive (not Google Cloud Storage), Encrypt, and Union by name.

Mergerfs (archived)

Mergerfs is no longer used as part of this setup. It has been replaced with an Rclone Union remote. See the archived Mergerfs version if you need it.

Media handling

While you are free to choose how to handle and rename your media, the author recommends using the built-in media handling and renaming in Sonarr/Radarr. Combined with a Union remote, this works seamlessly. This guide assumes you are not using an external tool such as Filebot or Olaris Rename.

Crontab

Crontab is a tool that allows you to run scripts automatically at a set interval. It will be used to automatically transfer files from the local temporary storage to the remote at an interval of your choice.

Directories

In the terminal, enter:

mkdir -p ~/mnt/media_merge ~/media_tmp ~/scripts

Setting up Rclone

Requirements

For this part you will need to have already prepared access to the Drive API. You will need a Client ID and Client Secret. More info can be found here.

Rclone setup is done through the terminal. You can connect via SSH or VNC.

Drive remote setup

  1. Open a terminal and type rclone config
  2. Type n for new remote.
  3. As name, type gdrive
  4. As storage, select Google Drive (not Google Cloud Storage) — reference by name, not number.

Note: You can use any storage solution you like, but this guide is based on Google Drive.

  1. Enter your Client ID. DO NOT skip this part.
  2. Enter your Client Secret. DO NOT skip this part.
  3. As scope, select full access.
  4. As root folder ID, leave blank.
  5. For service account file, leave blank.
  6. For edit advanced config, type n for no.
  7. For use auto config, type n for no.
  8. At this point you will be presented with a URL to enter in a browser and grant access with your Google account. You will then receive a validation code to paste back in the terminal.

Note: If you are using Google Workspace (formerly GSuite), grant access with your Workspace account, not your personal Google account.

  1. For configure as Shared Drive (Team Drive), type n for no.
  2. Verify that everything is OK and type y for yes.

Crypt remote setup

  1. While still in the rclone config screen, type n for new remote.
  2. As name, type gcrypt
  3. As storage, select Encrypt/Decrypt a remote — reference by name, not number.
  4. As remote, type gdrive: plus the root path of your media on Google Drive.

Example: If on Google Drive you have a folder named rclone and want to place your encrypted media inside it, enter gdrive:rclone

  1. As filename encryption, select standard.
  2. As directory name encryption, select true.
  3. As pass, type g for generate.
  4. As strength, type 128 for 128 bits.
  5. You will be presented with the generated password. Save it and DO NOT LOSE IT. Without this you will be unable to decrypt your media in the future.
  6. As salt, type g for generate.
  7. As strength, type 128 for 128 bits.
  8. You will be presented with the generated salt. Save it and DO NOT LOSE IT. Without this you will be unable to decrypt your media in the future.
  9. Verify that everything is OK and type y for yes.

Union remote setup

  1. While still in the rclone config screen, type n for new remote.
  2. As name, type union
  3. As storage, select Union merges the contents of several upstream fs — reference by name, not number.
  4. As upstreams, type gcrypt: :nc /home/HD/USERNAME/media_tmp

Note: Replace HD and USERNAME with your own values found on the dashboard.

  1. As action policy, leave blank for default.
  2. As create policy, leave blank for default.
  3. As search policy, leave blank for default.
  4. As cache time, leave blank for default.
  5. Verify that everything is OK and type y for yes.
  6. You are now done setting up your remotes. Type q to quit Rclone config.

Setting up scripts

Upload media

This script transfers media files from the temporary local directory to the remote. It will be run automatically via crontab.

In the terminal:

  • Type nano ~/scripts/uploadmedia
  • Paste in:
#!/bin/bash

echo "Moving local media files to remote..."
screen -dmS uploadmedia /usr/bin/rclone move ~/media_tmp gcrypt: --delete-empty-src-dirs -L -v --stats 5s
  • Press Ctrl+X, then Y, then Enter to save.
  • Type chmod +x ~/scripts/uploadmedia to make the script executable.

Startup script

This script starts your Rclone mount. It will also run automatically on any server restarts initiated by staff, and when you click Restart box on the control panel.

You will need a user agent string — just a random string of letters and numbers. It doesn't matter what it is.

In the terminal:

  • Type nano ~/.startup/gdrive
  • Paste in:
#!/bin/bash

USER_AGENT=XXXXXXXXXXXXXXXXX

export TMPDIR=$HOME/tmp
PID_FILE=$HOME/.config/rclone/rclone.pid

if [ -e $PID_FILE ]; then
    PID=`cat $PID_FILE`
    if ! kill -0 $PID > /dev/null 2>&1; then
        echo "Removing stale $PID_FILE"
        rm $PID_FILE
    fi
fi

/sbin/start-stop-daemon -S --pidfile $PID_FILE --make-pidfile -u $USER -d $HOME -b -a /usr/bin/rclone -- mount union: ~/mnt/media_merge --allow-other --user-agent="$USER_AGENT" --timeout 1h --vfs-cache-mode full
  • Replace the Xs with your own random string.
  • Press Ctrl+X, then Y, then Enter to save.
  • Type chmod +x ~/.startup/gdrive to make the script executable.

Shutdown script

This script shuts down your Rclone mount when required.

In the terminal:

  • Type nano ~/.shutdown/gdrive
  • Paste in:
#!/bin/bash

PID_FILE=$HOME/.config/rclone/rclone.pid
/sbin/start-stop-daemon --pidfile $PID_FILE -u $USER -d $HOME -K -a /usr/bin/rclone

if [ -e $PID_FILE ]; then
    PID=`cat $PID_FILE`
    if ! kill -0 $PID > /dev/null 2>&1; then
        echo "Removing stale $PID_FILE"
        rm $PID_FILE
    fi
fi
  • Press Ctrl+X, then Y, then Enter to save.
  • Type chmod +x ~/.shutdown/gdrive to make the script executable.

Setting up Crontab

Crontab will automatically run the upload script at your chosen interval.

In the terminal:

  • Type crontab -e
  • If prompted, select nano as your text editor.
  • Below the explanation in the crontab file, add:
0 3 * * * ~/scripts/uploadmedia

This will move media from the local temporary location to the remote every day at 3 AM (server time). Edit the timing to suit your schedule — refer to the explanation in the crontab file.

  • Press Ctrl+X, then Y, then Enter to save.

Final steps

At this point everything is set up. All that's left is to run your startup script and point your apps at the new virtual directory.

Because of the Union remote, your apps cannot distinguish between media in the local temporary location and media on the remote.

Union remote diagram

Mounting

This only needs to be done once, or in case of issues — mounts will auto-start on future box/server restarts.

In the terminal:

  • Type ~/.startup/gdrive
  • Type ps -ef and verify that rclone is in the list.

Sonarr / Radarr

First create the TV Shows and Movies directories if they don't already exist:

mkdir ~/mnt/media_merge/TV\ Shows
mkdir ~/mnt/media_merge/Movies

Root path

  1. Go to add a new TV show (or movie).
  2. In the root folder drop-down, select Add a new path.
  3. The browser picker does not work correctly — type your path manually:
    • Sonarr: /home/HD/USERNAME/mnt/media_merge/TV Shows
    • Radarr: /home/HD/USERNAME/mnt/media_merge/Movies

Note: Your home directory path can be found on the box control panel.

Plex

Restart Plex from the control panel before proceeding — it needs to be restarted to see the newly mounted directory.

  • In Plex, go to SettingsManage Libraries.
  • Create or edit the TV Shows and Movies libraries.
  • Point them at data/mnt/media_merge/TV Shows and data/mnt/media_merge/Movies respectively.

Extra — Prevent Plex from clearing your library on mount failure

By default Plex automatically removes metadata for media where files are missing. This is a problem when using a remote mount for two reasons:

  1. If the mount fails for any reason, Plex will clear your entire library.
  2. When Sonarr/Radarr performs a quality upgrade, Plex will clear out that show/movie.

To prevent this, go to Settings → Library in the Plex web interface and disable "Empty trash automatically after every scan". Plex will then mark missing media as trash instead of deleting it — when the mount is restored or the upgrade finishes, it will automatically be unmarked. The only downside is that when you intentionally remove media externally, you will need to manually empty trash in Plex as well.

Last Author
Clipper
Versions
35
Last Update
Sat, 11 Apr 2026 16:24:52 +0200