Uploading Documents to Google Drive via Command Line

I have a few different projects that are being ran on Raspberry Pi's that generated data daily that I wanted to backup to an Offsite solution. I have an onsite [cloud] solution but wanted to see if I could upload to a cloud solution such as Google Drive via command line.

There are several prebuilt solutions that already exist. I came across gDrive that was as simple as copying a token from your browser to the application and utilizing it. The GitHub page can be found here. https://github.com/gdrive-org/gdrive

Download gdrive

wget https://github.com/gdrive-org/gdrive/releases/download/2.1.0/gdrive-linux-rpi

Make Executable

chmod +x gdrive-linux-rpi

Install to Bin dir

sudo install gdrive-linux-rpi /usr/local/bin/gdrive

Get the Authorization Token

This will involve a machine with a browser. When you run the command gdrive list it will give you a URL to visit. Enter that url into a browser and authorize the app and paste the token that Google provides back into the command line.

Uploading Data

gdrive upload blog.tar.gz

gdrive upload file will upload the file to the authorized Google drive account. Once you have gdrive installed you will be able to setup a cron job that will upload the file(s) on a schedule to Google Drive.

Encrypting Data

Do note that depending on the data and other aspects in your environment, you may need to do some additional encrypting before uploading to Google Drive. GDrive does not provide an option of encrypting before uploading. There are other tools that will encrypt and upload for you or you can set the file(s) to be encrypted via a utility in the cron script.

Quick About

Hi, I am Michael Harrison. Devops/Developer for day job and father full time. I like machines such as 3d printers and like designing items for them.

Contact


E-mail: [email protected]
Phone: (765) 421-6199

Other Information


[Construction Icon]