Skip to content

Instructions to Re Purpose sync.sh

Claude Pageau edited this page Oct 22, 2016 · 14 revisions

sync.sh uses gdrive to upload (sync) files to a users google drive. I designed it to work with pi-timolo.py but the sync.sh code has recently been updated to be more generic and easier to re purpose.

gdrive runs with No dependencies so all you need is to download the file along with sync.sh if you wish. Note the use of sync.sh is optional but has important advantages.

  • Checks if gdrive is already running. Runs gdrive only if it is not already running to avoid spawning multiple instances
  • Kills gdrive processes if it has been running too long. default is > 4000 seconds or 67 minutes. (edit the sync.sh script if you need a different time to kill time period).
  • Optionally Looks for a pi-timolo.sync file created by pi-timolo.py indicating there are new files to sync otherwise it exits without attempting to resolve google drive files with specified local folder thus avoiding unnecessary sync handshaking when there are no changed or new files.
  • Runs a gdrive push to sync local folder with the specified google drive subfolder. Only changed and new files are transferred.
  • Reports if gdrive sync was successful or reports if errors were encountered
  • Optionally reboots system if pi-timolo.py is not running. I use this for headless remote operation. If you get a power spike or the camera for some reason hangs then this will recover. I have had remote camera's run unattended for several years and keeping my gdrive up-to-date.

Quick install files

Note: sync.sh is optional but recommended.

cd ~
wget -O sync.sh -q --show-progress https://raw.github.com/pageauc/pi-timolo/master/source/sync.sh
wget -O gdrive -q --show-progress https://raw.github.com/pageauc/pi-timolo/master/source/drive_armv6
# 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
sudo chmod +x sync.sh
sudo chmod +x gdrive
sudo cp gdrive /usr/local/bin
rm gdrive
gdrive version

Security Token Setup

gdrive needs to be setup with a security token to allow secure access to your google drive. This will create a hidden folder .gd

Please note that you need to change to the folder eg /home/pi that you want to represent the root for sync purposes per example below. This will avoid syncing unintended files. execute commands from a RPI ssh or gui terminal session.

mkdir ~/data-1
cd ~
gdrive init

Then follow the appropriate instructions on the following link to setup a security token and test connection. Note ignore references to pi-timolo.
gdrive security setup instructions here https://github.com/pageauc/pi-timolo/wiki/How-to-Setup-pi-timolo-gdrive-sync This token will be saved in the users /home/pi/.gd folder. To view a hidden folder use command ls ~./-al

Setup sync.sh

Use the nano editor to customize sync.sh. The following variables need to be reviewed and changed if necessary

SYNC_DIR=data-1 # folder location of files to sync
FILES_TO_SYNC='*' # Set the type of files to sync * for all
CHECK_FOR_SYNC_FILE=false # true if sync file required otherwise set to false
SYNC_FILE_PATH=$DIR/pi-timolo.sync # name of pi-timolo sync lock filename
FORCE_REBOOT=false # true to reboot if pi-timolo not running otherwise set to false

In this case we will not be using a sync lock file. This file is generated by pi-timolo.py whenever a new image is saved if the pi-timolo config.py motion detection settings variable createLockFile = True
For this example I will assume you are not using pi-timolo.py

Assuming your gdrive security token is setup and tests OK you can sync files in the /home/pi/data1 folder using sync.sh NOTE: make sure you have files in the data1 folder. From an RPI ssh or terminal session run sync.sh per the following

cd ~
./sync.sh

You should see gdrive handshaking and then file sync progress. If everything is successful you will see your data1 files on your google drive

gdrive list data1

Note if there are a lot of files in the folder then list won't work properly.

Clone this wiki locally