In this tutorial I will show you how to synchronize any files with your Raspberry PI using OneDrive as the example. For this project I am just going to synchronize my Documents folder from OneDrive. You can also use this for many other types of drives eg. Google Drive or Dropbox and the process is very similar. Just choose a different number in step 6.

  1. First open a Terminal window sand enter curl -L https://raw.github.com/pageauc/rclone4pi/master/rclone-install.sh | bash
  2. Once this has finished you are ready to configure rclone
  3. Enter the command rclone config
  4. Enter n (for a new connection) and then press enter
  5. Enter a name for the connection (i’ll enter onedrive) and press enter
  6. Enter 23 for OneDrive and press enter
  7. Press Enter for client ID
  8. Press Enter for Client Secret
  9. Press n and enter for edit advanced config
  10. Enter y for auto config (if you are on the Pi Directly) or n if you are logged in remotely through SSH and then press enter
    1. Only follow if your Pi doesn’t have a Desktop installed (Headless) – you will need to install rclone on a machine that has a desktop and web browser. (For windows 10 see the section at the bottom)
    2. Then run the command rclone authorize onedrive
    3. You then login, when you get success paste the result from the terminal window into your remote terminal. Then skip to step 13.
  11. A browser window will now open, log in with your Microsoft Account and select yes to allow OneDrive access.
  12. You will then see “success” and you can close the web browser
  13. Now choose 1 for OneDrive Personal or Business
  14. Now select the OneDrive you would like to use, you will probably only have one OneDrive linked to your account. This will be 0
  15. Now select y for yes
  16. Now select y for yes again to save the connection
  17. Close the terminal window
  18. Using a web browser or phone app, In your OneDrive create a folder to sync; i’ll call mine Documents
  19. Now we have set up the connection, however we still have to synchronize the folder with the raspberry PI. To do this we will write a simple .sh script and set it to run at a set time.
  20. First open a terminal and test your sync command. rclone sync -v onedrive:Documents /home/pi/Documents/Download This command will sync the “onedrive” connection “Documents” folder to your raspberry pi. The contents will be downloaded to you documents/Download (you may need to create this folder) folder on the pi. If successful you will see the terminal start downloading each file to the folder.
  21. Now let’s make the script. For this method you need to login to the pi directly, or use nano in the terminal to create the script file. If you’re comfortable with a text editor you can enter this string into the text editor on the raspberry pi and save it as sync.sh rclone sync -v onedrive:Documents /home/pi/Documents/Download
  22. If you have used different names to me, replace onedrive with your connection name and replace Documents with your onedrive folder name. You can also change the path, this is where the folder is synced to.
  23. Put the file in the /home/pi/Documents on your Raspberry Pi
  24. Now make the file executable, in the terminal enter chmod +x /home/pi/Documents/sync.sh
  25. This file will call the connection and download any new files from OneDrive.
  26. Now let’s make the script automatic. Open a terminal window and run the command crontab -e
  27. Select 2 for nano
  28. Enter the following string – 0 * * * * /home/pi/Documents/sync.sh
  29. Save the file (usually Ctrl + O to save and Ctrl + X to exit)
  30. That’s it! Restart your Raspberry Pi and add files to your OneDrive

I use this to synchronize photos to my raspberry pi Photo frame project.

UPDATE: To Upload files to Onedrive

If you would like to Upload files to OneDrive from your Raspberry PI, simply swap the source and destination.

rclone sync -v /home/pi/Documents/download onedrive:Documents/Download

If you would like to upload and download, I would suggest using 2 different folders. Then in step 21 add both commands to the text file.

rclone sync -v /home/pi/Documents/upload onedrive:Documents/upload

rclone sync -v onedrive:Document/download /home/pi/Documents/download

UPDATE: To use a folder with spaces

If you would like to use a folder name with spaces, simply put Quotation marks around the path.

rclone sync -v /home/pi/Documents/download “onedrive:My Documents”

UPDATE: To run rclone on windows 10 for step 10

  1. You can run rclone on windows 10 by downloading it from the rclone website https://rclone.org/downloads/ (Intel/AMD – 64 Bit).
  2. Extract the files and then open CMD.
  3. Navigate to that folder using the cd command (mine is cd C:\Users\Jarrod\Downloads\rclone-v1.53.3-windows-amd64\rclone-v1.53.3-windows-amd64). This is the folder that contains the rclone.exe file
  4. From here you can run the rclone authorize onedrive command. A web browser will appear and you can sign in to authorise. Then copy the key from that CMD to your headless raspberry pi to authorise.