Google Drive Client

Google Drive is a cloud-based storage solution available to all users on the cluster through their UMBC Google account (https://drive.google.com). The ‘drive’ client is a tool that simplifies copying local storage on the cluster to the users Google Drive. This tutorial covers the basics of the ‘drive’ client, for a much more in depth tutorial please check out this tutorial.

To gain access to the ‘drive’ client, load the following modules:

$ module load google-drive-client

To ensure the client is properly loaded and to see all available options type the following:

$ drive

To begin, you will want to mount a local directory to act as a staging area using the ‘init’ command, in this case I will be using a tmp/ directory in my homespace. The client will ask you to authorize your account through your browser and will then give you an authorization code to paste back into the client. On success you will have a “mounted” staging directory which you can write files to. All credentials are stored locally in a hidden folder inside the staging directory named ‘.gd’.

The process should look something like the following, first initialize the directory:

$ drive init tmp/
Visit this URL to get an authorization code
{URL HERE}
Paste the authorization code:

Open a browser and paste the given URL, which will then take you to a Google authorization page, similar to the following:

google-drive-agreement-1

Upon accepting the agreement, you will be taken to a page that will provide an authorization code that can then be pasted into the shell:

google-drive-authorized-1

Once you have authorized your account, you will access to many convenient features for example you can create a new folder from the command line, which I will use for further examples:

$ drive new --folder test

Now I will create change my directory to the staging area and create an example file:

$ cd ~/tmp
$ echo 'google drive test' > sample.txt

Now that an example file is created, let’s upload the file to our Drive:

$ drive push sample.txt

This will push the file to the root directory, but let’s move it to our test ‘tmp’ folder:

$ drive move sample.txt test/

We can combine these statements to effectively push local files directly to specific Drive folders:

$ drive push sample.txt; drive move sample.txt test/

Now that all of this is done, let’s try deleting and then retrieving ‘sample.txt’. From the staging directory, please note that pulling from a particular folder will reconstruct the entire directory path:

$ rm sample.txt
$ ls
$ drive pull test/sample.txt
...
$ ls tmp
sample.txt
$ cat ~/tmp/test/sample.txt
google drive test

Now let’s clean up and deinitialize our staging folder, make sure you are IN the staging folder:

$ rm test/sample.txt
$ rmdir test
$ drive deinit

That’s it, tutorial finished!