Sep 9, 2013

Backup my RPi using Google Drive

Here's how I setup gdrive in my Raspberry Pi to backup things I want to Google Drive.

Install GDrive
After update my RPi, I install some additional packages and also GDrive.
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install git cmake build-essential libgcrypt11-dev libjson0-dev libcurl4-openssl-dev libexpat1-dev libboost-filesystem-dev libboost-program-options-dev binutils-dev libboost-test-dev libqt4-dev libyajl-dev
 
$ git clone git://github.com/Grive/grive.git
$ cd ./grive
$ cmake .
$ make
 
$ mkdir ~/google_drive
$ cp ./grive/grive ~/google_drive

The 1st time to execute grive, I use the -a option in order to authenticate with Google. (You only have to do this once).

$ cd ../google_drive/
$ ./grive -a

The terminal will print out a very long URL. Copy and paste the URL to your browser, then click Accept button. From the browser, it will then print a long authentication code for you. Copy the authentication code an paste back to your terminal. Then the 1-time authentication is done.

Usually, I perform manual backup to my Google Drive. Just copy to google_drive folder and execute grive.

Below is an example of bash shell script to save your time.
#!/bin/bash
tar -zcvf /root/google_drive/backup_$(date +%y.%m.%d).tar.gz /etc
 
cd ./google_drive && ./grive
You may choose to setup a cronjob to execute the script as well.