Rclone is a command line program to manage files on cloud storage. It can back-up, restore and mirror data from or to the Cloud. (Google Drive, Dropbox, Amazon S3, …)
In this guide I will be mirroring a Google Drive folder in a directory on my Raspberry Pi 4 using the Rclone docker container. This guide assumed that you have already installed Docker and Docker Compose on your Raspberry Pi.
Step 1: Folder preparation
- Create local folders to store RClone configuration + where the Google Drive folder will be mounted
sudo mkdir -p /opt/rclone /mnt/drive && sudo chown -R $(id -u):$(id -g) /opt/rclone /mnt/drive
Step 2: Configure Rclone Google Drive remote
- Start configuring Rclone remotes (Google Drive)
docker run --rm -it \ --volume /opt/rclone:/config/rclone \ --volume /mnt:/data:shared \ --user $(id -u):$(id -g) \ rclone/rclone config
- Create a new remote called gdrive
No remotes found - make a new one n) New remote s) Set configuration password q) Quit config n/s/q> n name> gdrive
After providing a name, Rclone will ask you to select the desired storage. In my case I entered “13” (=Google Drive)
- Create API credentials for Google Drive
Follow the steps provided by the link that you are given or view them here.
- Select the “scope” that you want to use depending on your use case
Scope that rclone should use when requesting access from drive. Enter a string value. Press Enter for the default (""). Choose a number from below, or type in your own value 1 / Full access all files, excluding Application Data Folder. \ "drive" 2 / Read-only access to file metadata and file contents. \ "drive.readonly" / Access to files created by rclone only. 3 | These are visible in the drive website. | File authorization is revoked when the user deauthorizes the app. \ "drive.file" / Allows read and write access to the Application Data folder. 4 | This is not visible in the drive website. \ "drive.appfolder" / Allows read-only access to file metadata but 5 | does not allow any access to read or download file content. \ "drive.metadata.readonly" scope> 2
In my case I’m setting up a read-only folder, so I went for option number 2.
- Select Google Drive folder
ID of the root folder Leave blank normally. Fill in to access "Computers" folders (see docs), or for rclone to use a non root folder as its starting point. Enter a string value. Press Enter for the default (""). root_folder_id>
If you want to mount a particular Google Drive folder enter the ID, else you can leave this empty. The next commands up until “Remote config” can be continued using their default value.
- Remote config
In my case, I’m running this on a headless Raspberry Pi 4 which does not have any desktop functionality so I picked “N”. Follow the required steps.
Remote config Use auto config? * Say Y if not sure * Say N if you are working on a remote or headless machine y) Yes (default) n) No y/n> N Please go to the following link: <link-will-be-here> Log in and authorize rclone for access Enter verification code> REDACTED
- Team Drive
No, unless yes ;)
Configure this as a team drive? y) Yes n) No (default) y/n>
- Finishing up
Once you finished going through the last step, you will get a short summary which you just have to confirm. The newly created gdrive remote should be listed.
Current remotes: Name Type ==== ==== gdrive drive e) Edit existing remote n) New remote d) Delete remote r) Rename remote c) Copy remote s) Set configuration password q) Quit config e/n/d/r/c/s/q> q
Step 3: Mount Rclone gdrive remote
Please note that in my case I have a “Media” folder in the “root_folder_id” I have set in the previous step. If you do not have this folder you need to adjust (or remove) it from the command below:
docker run --rm \ --name rclone-gdrive-mount \ --volume /opt/rclone:/config/rclone \ --volume /mnt:/data:shared \ --user $(id -u):$(id -g) \ --volume /etc/passwd:/etc/passwd:ro \ --volume /etc/group:/etc/group:ro \ --device /dev/fuse \ --cap-add SYS_ADMIN \ --security-opt apparmor:unconfined \ rclone/rclone \ mount gdrive:Media /data/drive &
You should now have your Google Drive mounted in /mnt/drive on your local disk ;)