Xabi
Xabi
Dec 1, 2015 · 3 min read
Image by Engadget

Scenario

Can we really trust Google? Users and companies are using Google Drive to store all their files on the cloud more and more, without any other copy of their data. Is that secure?

This is a very controversial topic and is not the aim of this post to talk about that practice. Instead, I’d like to share a solution to download all our Google Drive data to our local computer or server.

Yes, I know; we can do that easily using the Drive client. But how to do that from Linux? And how to automatize also the backup of our Google Docs & Spreadsheets?

photo by Yuko Honda

Solution

Currently there is not any official Drive client for Linux. Instead, there are a lot of alternatives on GitHub.

My favorite one is Drive (very original name), which is very similar to git on its syntax. It was initially developed by @rakyll and currently there is a very active fork maintained by @Emmanuel T Odeke

odeke-em/drive project screenshot

Installation

Fortunately, the installation is quite easy on Ubuntu based distributions:

$ sudo add-apt-repository ppa:twodopeshaggy/drive
$ sudo apt-get update
$ sudo apt-get install drive

Alternatively, you also can get the latest code from Github, but remember that you need Go 1.3.x or higher. In order to do this on Ubuntu 14.04 I suggest you to download the binary package and to follow these instructions.

# Download and install Go
$ cd /tmp
$ wget https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz
$ tar -C /usr/local -xzf go1.5.1.linux-amd64.tar.gz
# Set the environment variables on you ~/.bashrc
export GOROOT=/usr/local/go
export GOPATH=$HOME/go-workspace
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
$ mkdir ~/go-workspace
$ sudo apt-get install git
$ go get -u github.com/odeke-em/drive/cmd/drive
# If you follow these steps, you should use `drive-google` command instead of `drive`

Configuration

Finally, we have to initialize the Drive directory, where we’ll store our files:

$ mkdir ~/gdrive
$ cd ~/gdrive
$ drive init
Visit this URL to get an authorization code https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=fsd3j2g2ff2g2gg2g2...
Paste authorization code:

Once we accept the request, we will have an authorization code that we have to paste in the console. Our credentials will be stored on “.gd/credentials.json”

Some examples

So now yes, we can start using drive:

# List the contents
$ drive list
# Download the contents
$ drive pull
# Upload our files
$ drive push
# More commands and help
$ drive help
...

Backup files

One of the most interesting features of this project is that we can export Google Docs and Spreadsheets to odt/doc/xls/… format.

$ drive pull -export odt,xls -no-prompt -verbose test
Resolving...
+ /test
+ /test/file3
+ /test/file2
+ /test/file1
Addition count 4
Pull::Started /test/file3
Pull::Started /test
Pull::Started /test/file2
Pull::Started /test/file1
Pull::Done /test
Pull::Done /test/file3
Exported '/home/myuser/gdrive/test/file2' to '/home/myuser/gdrive/test/file2_exports/file2.xls'
Exported '/home/myuser/gdrive/test/file1' to '/home/myuser/gdrive/test/file1_exports/file1.odt'
Pull::Done /test/file2
Pull::Done /test/file1

Note: this feature was recently improved. I recommend you to use the latest version from GitHub or to wait for 0.3.4 version release.

As you can see, it exports the files under filename_exports directory by default.

We can change that behavior adding -exports-dir parameter to the command or, still better, adding it to the .driverc configuration file:

# File: .drivercexports-dir=/home/myuser/gdrive-exports

If you don’t change the exports directory, you should avoid the synchronization of the exported documents using the .driveignore file:

# File: .driveignore_exports$
Image by Site Marca

Conclusion

Using Drive project and Cron, we can easily automatize the backup of our Google Drive files from Linux. If we need more and better backups, we always can save these files to Elkarbackup / Rsnapshot periodically :)

The Sysadmin

System Administration, GNU/Linux, Open Source

Xabi

Written by

Xabi

Hau ez du inork irakurriko

The Sysadmin

System Administration, GNU/Linux, Open Source

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade