If you have read my other project where I created a Raspberry Pi photo frame, then this is another extension of that. You could however use this to synchronize any files with your Raspberry PI. For this project I am just going to synchronize my sideshow photos from Google drive.

  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 drive) and press enter
  6. Enter 13 for Google Drive and press enter
  7. Press Enter for client ID
  8. Press Enter for client Secret
  9. Enter 1 and press enter
  10. Press Enter for ID of Root folder
  11. Press Enter for service account credentials
  12. Press n and enter for edit advanced config
  13. 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) – After pressing n, copy the link and paste into a web browser
    • You then login, when you get success paste the result from the terminal window into your remote terminal. Then skip to step 16.
  14. A browser window will now open, log in with your Google account
  15. You will then see “success”
  16. Using a web browser or phone app, In your Google drive create a folder for the images; I’ll call mine images. Also create a folder in your Raspberry Pi Documents folder called “download”
  17. Enter n for configure as team drive and press enter
  18. Enter y and press enter to add the connection
  19. Close the terminal window
  20. 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.
  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 drive:images /home/pi/Documents/Download
  22. If you have used different names to me, replace drive with your connection name and replace images with your 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 script executable, in the terminal chmod +x /home/pi/Documents/sync.sh
  25. This file will call the connection and download any new files from Google Drive. 
  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, this runs once an hour – 0 * * * * /home/pi/Documents/sync.sh
  29. Save the file (usually Ctrl + O to save and Ctrl + X to exit)
  30. Thats it! Restart your Raspberry Pi and add some photos to your Google drive

PS. You can also use this for many other types of drives and the process is very similar. Just choose a different number in step 6.

UPDATE: TO UPLOAD FILES TO Google Drive

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

rclone sync -v drive:images /home/pi/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 drive:images/upload

rclone sync -v drive:images/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 “onedrive:My Documents”