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.
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.
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
git clone git://github.com/Grive/grive.git
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.
sudo chmod 777 ~/gdrive -R
cp ~/installs/grive/grive/grive ~/gdrive
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.
Paste in the following (Obviously replacing your paths to match your system)
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/
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!