Google Drive syncing on Ubuntu

Google Drive
Google Drive is a perfect choice for performing web server backups. There’s no official linux client as far as I can make out but fortunately for us there is an open source implementation called “Grive” that does exactly what we want! This is my preferred backup provider currently as it gives 15G of space! Way more space than Dropbox and it seems a lot more stable.

Pre-requisites

Sign-up for Google Drive Api

You will need to go sign-up and enable Drive API on your google account. Generate a Server API Key, providing the ip address of your web server to google when creating it. Then proceed with the steps below.

System Packages

You will need a number of packages installed in order to build grive from source. If you followed my linode installation guide you should have everything you need, but you can run this command anyways just to make sure we did not miss something.

sudo apt-get install cmake libjson0-dev make gcc libboost1.55 libexpat1 libexpat1-dev libyajl-dev libyajl2 git cmake libgcrypt11-dev libjson0-dev libcurl4-openssl-dev build-essential automake autoconf libtool pkg-config libcurl4-openssl-dev intltool libxml2-dev libgtk2.0-dev libnotify-dev libglib2.0-dev libevent-dev checkinstall libqt4-dev

Install & Setup Grive

Build from source

Now we need to download the grive source code

cd ~/installs
git clone git://github.com/Grive/grive.git
cd grive
cmake .
make

If that all went well, you should be good to go. Now we need to do the initial configuration, first copying grive into a new folder that will house all our synced files.

mkdir ~/gdrive
sudo chmod 777 ~/gdrive -R
cp ~/installs/grive/grive/grive ~/gdrive
./grive -a

This will output a web url that you need to copy and paste into a browser. I think the only requirement here is that you are logged into Google under the account you wish to have it be linked to and make sure you have Drive API access enabled before you do this. It will display a validation code that you then need to copy and paste back into the terminal then press enter.

It will then proceed to sync the ./grive executable to your google drive. Unfortunately I have not found a way around this so just leave it be.

Setup Cron For Unattended Syncing

We need to add a line in crontab to execute grive every minute to sync files. But first we will create a bash script to execute grive. If you are going to set up automatic mysql backups as well (which I outline in another article) you will need it setup this way.

mkdir ~/scripts
nano ~/scripts/grive.sh

Paste in the following (Obviously replacing your paths to match your system)

#!/bin/bash

cd /home//gdrive
./grive

Now make it executable

sudo chmod +x ~/scripts/grive.sh

Now we add the crontab entry for it.

sudo crontab -e

Then add this line at the end of the file

* * * * * cd /home//scripts/ && ./grive.sh

That should be it. You should be good to go. Test it by copying a file to ~/gdrive and then verify on the google drive website that the file was synced!

Posted in Server Admin Tagged with: , , , , , , , , , , ,
One comment on “Google Drive syncing on Ubuntu
  1. TJ says:

    PS: Website in progress…

    This API looks useful and pretty cool. I think I will implement it in one of my big projects I am making related to cloud servsers and storage. I am very into server work and admin work.

    TJ

2 Pings/Trackbacks for "Google Drive syncing on Ubuntu"
  1. […] feature goes perfectly with my previous article on Google Drive Syncing. If you pair it with these automatic backups you can have your mysql backups automatically sync to […]

  2. […] I have a newer updated version of this guide on my new blog. It’s very similar but a little different and has a bit more detail, you can read it here. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*