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?
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
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
$ 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`
Finally, we have to initialize the Drive directory, where we’ll store our files:
$ mkdir ~/gdrive
$ cd ~/gdrive
$ drive initVisit 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”
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...
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
Addition count 4
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'
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$
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 :)