Leave a Comment
I’ve been looking at several linux projects here recently, such as LibreNMS, and you’ll need to be sure you are backing them up. I wanted to quickly backup a compressed copy of my LibreNMS install and so I went looking for a super easy way to upload a file to Google Drive, and I found it with gdrive.
gdrive, not to be mistaken for Google Drive itself, is a command line tool by Petter Rasmussen for Linux, Windows and OSX. Just what I needed. It’s proved itself so useful that I can’t imagine how I lived without it.
Linux
- SSH on to your linux box and download the Linux version of gdrive from GitHub.
12cd ~wget https://docs.google.com/uc?id=0B3X9GlR6EmbnWksyTEtCM0VfaFE&export=download - You should see a file in your home directory called something list uc=0B3X9GlR6EmbnWksyTEtCM0VfaFE. Rename this file to gdrive.
1mv uc\?id\=0B3X9GlR6EmbnWksyTEtCM0VfaFE gdrive - Assign this file executable rights.
1chmod +x gdrive - Install the file to your usr folder.
1sudo install gdrive /usr/local/bin/gdrive - You’ll need to tell Google Drive to allow this program to connect to your account. To do this, run the gdrive program with any parameter and copy the text it gives you to your browser. Then paste in to your SSH window the response code that Google gives you.Run the following.
1gdrive list - YOU ARE DONE! Now you can upload files as required.
1gdrive upload backups.tar.gz
Windows
- Download the Windows version of gdrive from github.
- Copy the gdrive-windows-x64.exe file to your c:\windows folder
1copy downloads\gdrive–windows–x64.exe c:\windows - Run gdrive with a parameter to get the Google authentication code and then copy that to a browser windows. Paste back the verification code.
- Now upload a file. WOOOT!
1gdrive–windows–x64.exe upload c:\test\backup.zip
Common Switches
GDrive supports a load of useful features which you should take a look at. The follow are grabbed from the gDrive page at git.com.
Upload file or directory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
gdrive [global] upload [options] <path>
global:
–c, —config <configDir> Application path, default: /Users/<user>/.gdrive
—refresh–token <refreshToken> Oauth refresh token used to get access token (for advanced users)
—access–token <accessToken> Oauth access token, only recommended for short–lived requests because of short lifetime (for advanced users)
options:
–r, —recursive Upload directory recursively
–p, —parent <parent> Parent id, used to upload file to a specific directory, can be specified multiple times to give many parents
—name <name> Filename
—no–progress Hide progress
—mime <mime> Force mime type
—share Share file
—delete Delete local file when upload is successful
—chunksize <chunksize> Set chunk size in bytes, default: 8388608
|
Download file or directory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
gdrive [global] download [options]
global:
–c, —config Application path, default: /Users//.gdrive
—refresh–token Oauth refresh token used to get access token (for advanced users)
—access–token Oauth access token, only recommended for short–lived requests because of short lifetime (for advanced users)
options:
–f, —force Overwrite existing file
–r, —recursive Download directory recursively, documents will be skipped
—path Download path
—delete Delete remote file when download is successful
—no–progress Hide progress
—stdout Write file content to stdout
|
List files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
gdrive [global] list [options]
global:
–c, —config Application path, default: /Users//.gdrive
—refresh–token Oauth refresh token used to get access token (for advanced users)
—access–token Oauth access token, only recommended for short–lived requests because of short lifetime (for advanced users)
options:
–m, —max Max files to list, default: 30
–q, —query Default query: “trashed = false and ‘me’ in owners”. See https://developers.google.com/drive/search–parameters
—order Sort order. See https://godoc.org/google.golang.org/api/drive/v3#FilesListCall.OrderBy
—name–width Width of name column, default: 40, minimum: 9, use 0 for full width
—absolute Show absolute path to file (will only show path from first parent)
—no–header Dont print the header
—bytes Size in bytes
|
Share file or directory
1
2
3
4
5
6
7
8
9
10
11
12
13
|
gdrive [global] share [options]
global:
–c, —config Application path, default: /Users//.gdrive
—refresh–token Oauth refresh token used to get access token (for advanced users)
—access–token Oauth access token, only recommended for short–lived requests because of short lifetime (for advanced users)
options:
—role Share role: owner/writer/commenter/reader, default: reader
—type Share type: user/group/domain/anyone, default: anyone
—email The email address of the user or group to share the file with. Requires ‘user’ or ‘group’ as type
—discoverable Make file discoverable by search engines
—revoke Delete all sharing permissions (owner roles will be skipped)
|