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.
- 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 drive) and press enter
- Enter 13 for Google Drive and press enter
- Press Enter for client ID
- Press Enter for client Secret
- Enter 1 and press enter
- Press Enter for ID of Root folder
- Press Enter for service account credentials
- 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) – 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.
- A browser window will now open, log in with your Google account
- You will then see “success”
- 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”
- Enter n for configure as team drive and press enter
- Enter y and press enter to add the connection
- Close the terminal window
- 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.
- 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
- 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.
- Put the file in the /home/pi/Documents on your Raspberry Pi
- Now make the script executable, in the terminal chmod +x /home/pi/Documents/sync.sh
- This file will call the connection and download any new files from Google Drive.
- Now let’s make the script automatic. Open a terminal window and run the command crontab -e
- Select 2 for nano
- Enter the following string, this runs once an hour – 0 * * * * /home/pi/Documents/sync.sh
- Save the file (usually Ctrl + O to save and Ctrl + X to exit)
- 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”