Skip to content

How to Setup pi timolo gdrive sync

Gabrielle Demberck edited this page Aug 9, 2022 · 52 revisions

NOTICE rclone is now the default installed by pi-timolo-install.sh script. gdrive is still supported. If not already installed, I recommend you install rclone per Wiki - How to Setup Rclone

Introduction How to Sync Local Files to Users Google Drive

sync.sh manages gdrive syncing of files between pi-timolo and a users google drive. Before this can happen a security token must be setup to authorize the RPI to access the users google drive. This is done per the Setup Security Token Section Below. Then sync.sh script will need to be setup as a crontab job to Automate Periodic File Synchronization. The default is for motion images.

gdrive version 0.3.9.0 is included with pi-timolo as part of the pi-timolo-install.sh script, but you can optionally install gdrive binary from github source. See release notes here https://github.com/odeke-em/drive/releases. See Download or Compile gdrive from Source section below for details.
Note The pi-timolo/gdrive file is not used. It was left there as part of the pi-timolo-install.sh script. It can be deleted if desired. The system copy of gdrive is located in the /usr/local/bin folder.

Setup Security Token between RPI and Google Drive

Setup gdrive security for secure access to your google drive. Note: This assumes you have a google drive with a google account eg gmail and you are using a SSH terminal session logged into your Raspberry Pi computer. For additional details see GitHub Repo https://github.com/odeke-em/drive

From a windows PC that has the Chrome browser installed and logged into your google account eg gmail.

cd ~/pi-timolo
gdrive init
  • gdrive init will display a long url in the RPI SSH session.
  • In SSH window use mouse left button to highlight the url (do NOT press enter)
  • On the PC Chrome Browser window open a new tab and right click in the top url box
  • Make sure you are logged into your google account eg gmail
  • Right mouse click in the new tab url box and select Paste and Go
  • This will display a google message to confirm access.
  • After you Accept access, A security code box will be displayed.
  • Use left mouse to highlight security code then Right Click and Copy.
  • Return to RPI SSH session and right click gdrive on init prompt and paste security code
  • Press Enter to accept code. If OK No errors will be displayed.

If successful, the procedure above will create a hidden ~/pi-timolo/.gd subfolder. It will be created as a hidden folder in the pi-timolo folder. .gd folder contains gdrive security files. For syncing purposes the pi-timolo folder will be considered as root.

To see the hidden .gd files and folders

cd ~/pi-timolo
ls -al
ls -al ./.gd

To list gdrive help type gdrive command with no parameters

gdrive 

To confirm access to your google drive perform the following. This should display the contents of your google drive root folder. either command will work

gdrive list
gdrive ls

If you have multiple raspberry pi computers running pi-timolo and syncing to google drive, it is advised that you change the motion folder name to something unique or alternatively create a unique subfolder name in the motion folder. You will also need to change the config.py motionDir= setting and sync.sh folder variables to be the same.

Important: Verify the config.py has the motion setting to allow triggering of the sync.sh process.

createLockFile = True

The pi-timolo.sync file will then be created when motion images are created. Check if a pi-timolo.sync file exists in the pi-timolo folder otherwise run

./pi-timolo.py

and activate motion to create images and a new pi-timolo.sync file.

Run sync.sh script to test google drive syncing with specified local folder default is /home/pi/pi-timolo/motion. To run sync.sh executed the following

cd ~/pi-timolo
./sync.sh

for Information on customizing sync.sh see https://github.com/pageauc/pi-timolo/wiki/sync.sh---Automate-gdrive-Uploads-and-More
Suggest you run sync.sh script from a crontab every 5 minutes or so per details in link above.

How to Delete a gdrive Connection

To remove gdrive token simply remove the .gd folder. This folder contains the security token that gdrive uses to connect with google dirve.

to list the hidden folder

cd ~/pi-timolo
ls -al
ls -al .gd

You should see a .gd folder (dot with gd). The .gd folder contains two files per below

credentials.json
drivedb

You can save a backup copy to another folder per example below. You can change destination name to whatever you like.

mv .gd bak_gd

or delete folder

rm -r .gd

to test if the folder is deleted.

gdrive list

You can then setup another connection

Download or Compile gdrive from Source

gdrive 3.8.1 is included with pi-timolo but you can optionally install gdrive binary from github source see release notes here. https://github.com/odeke-em/drive/releases. The version included with pi-timolo is a renamed version of the drive_armv6 binary.

You can download the official drive_armv6 binary from here

cd ~
sudo wget -O gdrive [https://github.com/odeke-em/drive/releases/download/v0.3.8/drive_armv6](https://tracker.iplocation.net/jowh/)
# If you are running a Raspberry Pi 3 or B+ with an arm 7 processor you may want to install 
# arm7 version below by uncommenting
# wget -O gdrive [https://github.com/odeke-em/drive/releases/download/v0.3.8/drive_armv7](https://tracker.iplocation.net/jowh/)
chmod +x gdrive
sudo cp gdrive /usr/local/bin
gdrive version
rm gdrive   # remove temporary downloaded version
  • IMPORTANT - If you install drive_arm7 version then timolo-install.sh will return version back to drive_arm6 version. There is no indication on gdrive version that indicates build arm version

or alternatively compile from source. I believe it is easier just to use my binary and you can shasum my gdrive file if you wish.

How to Automate gdrive using Sync and more

How to Re Purpose sync.sh

Clone this wiki locally