Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to synchronize with Google Drive #4

Closed
malcolmct opened this issue Oct 15, 2015 · 16 comments
Closed

How to synchronize with Google Drive #4

malcolmct opened this issue Oct 15, 2015 · 16 comments
Labels

Comments

@malcolmct
Copy link

motionEyeOS is great, but having seen a number of requests for Google Drive functionality, I thought I should share how I got it working.

Here are step-by-step instructions which also work with motionPie:

  • Ensure that you have set a motionEyeOS admin password through the web interface and have rebooted
  • Using SSH, login as root with your admin password from a Mac, Linux or Windows PC
  • Enter and execute the following commands. You can do so one line at a time or just copy and paste
    the whole block into your SSH session:
# mount the root volume as read/write
mount -o remount,rw /
# change to the /usr/bin directory where we will keep the gdrive executable
cd /usr/bin
# download a pre-built gdrive binary file
wget https://github.com/odeke-em/drive/releases/download/v0.2.2-arm-binary/drive-arm-binary
# make it executable
chmod +x drive-arm-binary
# rename it to gdrive
mv drive-arm-binary gdrive
# change the root volume back to read-only
mount -o remount,ro /
# create a gdrive directory on the data volume
mkdir /data/gdrive
# change to that directory
cd /data/gdrive
# download Emil Janesten's greatly improved version of Claude Pageau's sync.sh script 
wget https://gist.githubusercontent.com/Limeliz/4389cc40744331736c59/raw/bee4809bcf3a8eef01a9d8394d996eaf4d8ae1ec/sync.sh
# make the script executable
chmod +x sync.sh
# create a symbolic link to the motion output folder
ln -s /data/output output
  • Now you'll want to link gdrive to your Google account. Open a browser on your PC and ensure
    that you are logged into Google (for example, you could open Gmail).

Back in your SSH session, enter and execute:

gdrive init

This will produce a long, complex URL which you should copy and paste into your PC browser's
address line, then press Enter.

You'll need to give permission to manage files in your Google Drive and will then be returned a
code to copy back into your SSH session where gdrive is waiting.

A success will return nothing.

  • Finally, you should add a cron entry to copy over files from the motion output folder to Google
    Drive on a regular schedule.
    # set the crontab editor to be nano (I'm much more comfortable with nano than vi)
      export EDITOR=nano
    # enter crontab editor
      crontab -e
  • Now set the task to run every five minutes by pasting in:

*/5 * * * * /data/gdrive/sync.sh >> /data/log/gdrive_output.log 2>&1

Then quit nano with control-x and save the crontab entry.

That's it. You can have it up and running in about five minutes and it seems to work without any
unforeseen problems.

***Modified on 11-20-2015 to incorporate changes suggested by Limeliz

@ccrisan
Copy link
Collaborator

ccrisan commented Oct 15, 2015

Nice. Thanks!

@Volyova
Copy link

Volyova commented Oct 16, 2015

Looks awesome. Will try that out.

@Limeliz
Copy link

Limeliz commented Nov 8, 2015

Awesome! I just went through all steps and althought I've had a RPI for just two days and never used any Linux-system before everything seems to be working. gdrive is uploading all photos and video right now. :-) 👍

@russellgeoff
Copy link

Thanks for these instructions! I really like being able to reference and store my photos on my Google Drive.

I am having an issue when the images are uploaded to Google Drive. It appears that each upload generates a new folder for the images. This has caused my output folder to explode with repeated folders. It also appears that the same images are being uploaded to multiple folders repeatedly. I've included images of the issues below. Any help resolving this would be great! Thank you!

Folders on my PC:
image

Folders on Google Drive:
image

Same image uploaded multiple times:
image

@Limeliz
Copy link

Limeliz commented Nov 19, 2015

I've ran into two problems. Everything worked for a couple of days, but then it stopped working.

  1. The photos has stopped uploading to Google Drive. Last activity was 12th november. When runnig sync.sh manually I see that gdrive is unable to connect to the internet. Althought I'm connected to the same wifi as the RPI and I'm able to connect.
  2. When I ran sync.sh manually I saw an error saying that 'pgrep' could not be found (line 17 in the script). When trying to run pgrep manually I see that indeed it's not on the RPI. I'm new to *nix systems, but Googling has taught me what it's used for. Is there a way to download this tool from someplace so I can use it in MotoinEyeOS?

@MotionUK
Copy link

Good Morning Limeiz,

Looking at the cron task i noticed that the data dump does not point to the correct location.

"*/5 * * * * /data/gdrive/sync.sh >/dev/nul"

the /dev/nul should read as /dev/null.....

also look at

http://unix.stackexchange.com/questions/163352/what-does-dev-null-21-mean-in-this-article-of-crontab-basics

I'm currently sitting a Linux certification When I looked at the device folder (/dev) the /nul was not present in the OS.

Worth a shot............

MotionUK

@MotionUK
Copy link

@malcolmct - thanks for an amazing contribution. MotionUK

@Limeliz
Copy link

Limeliz commented Nov 19, 2015

@MotionUK Yeah, I noticed that "/dev/nul" was typed wrong, after googling about it for a few minutes. I've already corrected that. The weird thing is that it worked for a couple of days and then suddenly stopped working. I'll try and reinstall the whole thing and see if that helps. I'll get back here with the results. There shouldn't exist any folder called /dev/null, it's a "black hole" which is commonly used on *nix systems to dump data which you don't want to use. It simply makes sure that any output sync.sh produces is being discarded and not displayed.

@Limeliz
Copy link

Limeliz commented Nov 20, 2015

It seems like my cron wasn't running. The following made gdrive start syncing.

crond stop
crond start

I also edited the sync.sh script a bit, because I noticed it ran gdrive three times every cron instance. By using this (http://unix.stackexchange.com/questions/22044/correct-locking-in-shell-scripts) method with a lockfile I make sure the script is only running one instance. Here's my version of sync.sh: https://gist.github.com/Limeliz/4389cc40744331736c59

Oh, and I noticed from the gdrive output logs (I've got my crontab setup like this, to debug the sync.sh outputs: */5 * * * * /data/gdrive/sync.sh >> /var/log/gdrive_output.log 2>&1) that there was a problem with syncing of /data/gdrive/output/lastcapture.jpg (or whatever the filename was). I deleted the file and it's not producing any more errors now.

@russellgeoff I also had a problem with duplicate files and folders. I'm not sure if it was because gdrive was running multiple instances, but adding -ignore-name-clashes to the gdrive-line in sync.sh removed all duplicates.

@malcolmct
Copy link
Author

@Limeliz Many thanks for your comments and improvements!

I've modified my original posting to incorporate Limeliz's changes. I also point to his version of the sync.sh script. I think I must have originally tested mine on Raspian and hadn't noticed the absence of pgrep in MotionEyeOS.

@mastix
Copy link

mastix commented Jan 17, 2016

I've updated the Limeliz's sync script to also pull changes (including deletions) from Google Drive. This allows to delete files and folders in Google Drive and these files will then be deleted from MotionEyeOS as well.

Just in case you're interested: https://gist.github.com/mastix/1a93fb8c6114a3ba79ed

@ParthPatel-ES
Copy link

amazing work
thanks for sharing
In raspberry pi 2 works fine everything is perfect.

@xhain
Copy link

xhain commented Dec 19, 2016

Thanks for this!

@bortek
Copy link
Collaborator

bortek commented Feb 23, 2017

I have added a separate page on Wiki with the How-To above therefore closing this issue.

@Johnrasp
Copy link

There is no 'wget' in motionEYE OS
ref google drive #4
wget https://github.com/odeke-em/drive/releases/download/v0.2.2-arm-binary/drive-arm-binary
error is -sh: wget: command not found

@jasaw
Copy link
Collaborator

jasaw commented Jul 26, 2019

Use curl.
curl -o

ccrisan pushed a commit that referenced this issue Sep 29, 2019
Add fixes for some of the build failures caused by strict-overflow
warnings. Patches #1, #2, and #4 are upstream. Patch #3 is pending
upstream.

Fixes:
http://autobuild.buildroot.net/results/923/9239f230629ca4e381af5e8f43989997d9bfde99/
http://autobuild.buildroot.net/results/618/6187b92bcdfd9281683c37906ae74f2e0c5e6d0e/
http://autobuild.buildroot.net/results/9eb/9eb5ed92a923f0c038e3d913289eddc1cda1b62f/

Cc: Scott Fan <fancp2007@gmail.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests