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.
- First open a Terminal window sand enter curl -L https://raw.github.com/pageauc/rclone4pi/master/rclone-install.sh | bash
- Once this has finished you are ready to configure Rclone
- Enter the command rclone config
- Enter n (for a new connection) and then press enter
- Enter a name for the connection (i’ll enter onedrive) and press enter
- Enter 18 for OneDrive and press enter
- Press Enter for client ID
- Press Enter for Client Secret
- Press n and enter for edit advanced config
- 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
- 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.
- Then run the command rclone config “onedrive”
- You then login, when you get success paste the result from the terminal window into your remote terminal. Then skip to step 13.
- A browser window will now open, log in with your Microsoft Account and select yes to allow OneDrive access.
- You will then see “success” and you can close the web browser
- Now choose 1 for OneDrive Personal or Business
- Now select the OneDrive you would like to use, you will probably only have one OneDrive linked to your account. This will be 0
- Now select y for yes
- Now select y for yes again to save the connection
- Close the terminal window
- Using a web browser or phone app, In your OneDrive create a folder to sync; i’ll call mine Documents
- 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.
- 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.
- For this method you need to login to the pi directly. Now lets make it automatic. If your comfortable with a text editor you can enter this string into leafpad on the raspberry pi and save it as sync.sh rclone sync -v onedrive:Documents /home/pi/Documents/Download
- If you have used different names to me, replace onedrive with your connection name and replace Documents with your folder name. You can also change the path, this is where the folder is synced to.
- Put the file in the /home/pi/Documents on your Raspberry Pi
- Make it Executable, in the terminal chmod +x /home/pi/Documents/sync.sh
- This file will call the connection and download any new files from OneDrive.
- Only follow if your Pi doesn’t have a Desktop installed (Headless) or you have installed Raspian Buster– Run crontab -e in the terminal
- Select 2 for nano
- Enter the following string – 0 * * * * /home/pi/Documents/sync.sh
- Save the file ( usually Ctrl + O to save and Ctrl + X to exit) ,then skip to step 33
- (Depreciated, Gnome Schedule has been removed as of Raspian Buster. Only use if you have an older version. Use step 24.i if you have Raspian Buster or newer) Next we will install a tool to set the script to run automatically. Open a terminal and enter sudo apt-get install gnome-schedule
- Enter your password and once the installation is completed close the terminal
- Open the Raspberry Pi menu and under System Tools open Scheduled Tasks
- Select New and then A Task that launches recurrently
- Enter a Description if you like. In the command box enter /home/pi/Documents/sync.sh
- Next you can enter the times for synchronization, i’m going to leave it as default; which syncs every hour. Feel free to change this to your liking
- Then Click add
- 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 onedrive:Documents
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/downloads
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 “onedrive:My Documents”