Aller au contenu

Rclone - Monter un stockage cloud (Google Drive, Dropbox, ...)

Sources

https://rclone.org/dropbox/ https://rclone.org/gui/ *https://www.jamescoyle.net/how-to/3116-rclone-systemd-startup-mount-script

Préparation d'un compte Google

Nous allons devoir configurer le compte Google pour qu'il accepte la connexion que nous créerons.

Create a service account for example.com

To create a service account and obtain its credentials, go to the [Google Developer Console](https://console.cloud.google.com).
You must have a project - create one if you don't and make sure you are on the selected project.
Then go to "IAM & admin" -> "Service Accounts".
Use the "Create Service Account" button. Fill in "Service account name" and "Service account ID" with something that identifies your client.
Select "Create And Continue". Step 2 and 3 are optional.
Click on the newly created service account
Click "Keys" and then "Add Key" and then "Create new key"
Choose type "JSON" and click create
This will download a small JSON file that rclone will use for authentication.

If you ever need to remove access, press the "Delete service account key" button.

Allowing API access to example.com Google Drive

Go to example.com's Workspace Admin Console
Go into "Security" (or use the search bar)
Select "Access and data control" and then "API controls"
Click "Manage domain-wide delegation"
Click "Add new"
In the "Client ID" field enter the service account's "Client ID" - this can be found in the Developer Console under "IAM & Admin" -> "Service Accounts", then "View Client ID" for the newly created service account. It is a ~21 character numerical string.
In the next field, "OAuth Scopes", enter https://www.googleapis.com/auth/drive to grant read/write access to Google Drive specifically. You can also use https://www.googleapis.com/auth/drive.readonly for read only access.
Click "Authorise"

Installation de rClone

Pour installer rClone, lancer la commande suivante :

curl https://rclone.org/install.sh | sudo bash

Configuration de rClone

Lancer cette commande :

rclone config

  • n > New remote
  • Enter a name (Example : Google_Drive)
  • Choose a number (20 for Google Drive)
  • client_id : leave blank
  • client_secret : leave blank
  • Scope : Choose 1 (full access)
  • service_account_file : leave blank
  • Edit advanced config : no
  • Use web browser to automatically authenticate rclone with remote ? : Y if a GUI is available or N if no GUI. If no GUI, rclone will send something like this :
    rclone authorize "drive" "eyJdY19aZPO6IdTyaEslIn6"
    

Execute this from a computer that have rclone installed and a GUI. Rclone can be downloaded from https://rclone.org/downloads/, even for Windows. A web page should open. Authorize the access to the Google account. When it's done, come back to the command line on the computer that have a GUI. A message like this should appear :

Got code Paste the following into your remote machine ---> eyJ0b2tlbiI6InXXXXXXXIn0 <---End paste Copy this code and paste it on the machine where Google Drive will be mounted. Rclone should be like waiting for it, saying "config_token> " Leave other two options blank again then quit Rclone when it's back to the list of remote available drives.

Monter le stockage distant au démarrage du serveur

Le script suivant permet de monter automatiquement le stockage distant lors du redémarrage du serveur :

#!/bin/bash

# Montage du Google Drive avec rclone
rclone mount Google_Drive: /CLOUDS/Google_Drive \
    --allow-other \
    --dir-cache-time 1000h \
    --vfs-cache-mode writes \
    --uid 0 \
    --gid 0 &
Le rendre exécutable avec la commande chmod +x /DOSSIER/script.sh puis exécuter crontab -e pour ajouter la ligne suivante afin qu'il s'exécute à chaque redémarrage du serveur :
@reboot /SCRIPTS/mount_rclone_Google_Drive.sh