We all are worried about our data and would opt to have a backup. But it seems to be a bit expensive when it comes with third party backups or an extra drive for backup. So why don’t we consider one of our Google Drive as backup drive. Gmail offers upto 15GB storage space for backup drive, which would be enough for a start up to configure backups. Here in this article I would explain how we can configure google drive on our linux servers an use it to upload backup.
GDrive
Gdrive is a command line tool which manages, uploads, downloads, deletes and shares files on Google Drive. You can download the tool from Github at https://github.com/prasmussen/gdrive.
Unfortunately it does not support file synchronisation.
Installation
Download the binary package from the github website and install
sudo mv drive /usr/local/bin/gdrive
Alternatively you can install from source code. Next, simply run drive and it will provide you a URL which authenticates you using OAuth.
Configuring gdrive
[email protected] [/root]# gdrive list https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=367116sdf323e23221053-7n0vf5akeru7on6o2fjinrecpdoe99eg.apps.googleusercontent.com&redirect_uri=urn%3Afdietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%df3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=state Paste the authorization code:
you will get a unique URL to authorize gdrive with your google drive. Open your google drive in your browser and visit the URL specified in the output. This will ask you to authorize and click on allow. Once done, you will get a unique authorization code. Paste it there and press enter. Done !!
Now your server is authorized to upload/dowload/list the contents of your google drive. You can use the following commands to work with gdrive. A simple bash script to create backup and upload to grive will now help you to upload the contents.
Usage
gdrive [global options] <verb> [verb options]
Options
Global options:
-a, --advanced Advanced Mode -- lets you specify your own oauth client id and secret on setup
-c, --config Set application path where config and token is stored. Defaults to ~/.gdrive
-v, --version Print version
-h, --help Show this help
Verbs:
delete:
-i, --id File Id (*)
download:
-i, --id File Id (*)
-s, --stdout Write file content to stdout
--pop Download latest file, and remove it from google drive
folder:
-t, --title Folder to create (*)
-p, --parent Parent Id of the folder
--share Share created folder
info:
-i, --id File Id (*)
list:
-m, --max Max results
-t, --title Title filter
-q, --query Query (see https://developers.google.com/drive/search-parameters)
-s, --shared Show shared status (Note: this will generate 1 http req per file)
-n, --noheader Do not show the header
share:
-i, --id File Id (*)
unshare:
-i, --id File Id (*)
upload:
-f, --file File or directory to upload (*)
-s, --stdin Use stdin as file content (*)
-t, --title Title to give uploaded file. Defaults to filename
-p, --parent Parent Id of the file
--share Share uploaded file
url:
-i, --id File Id (*)
-p, --preview Generate preview url (default)
-d, --download Generate download url
Examples
List files
$ gdrive list
Id Title Size Created
0B3X9GlR6EmbnenBYSFI4MzN0d2M drive-freebsd-amd64 5 MB 2013-01-01 21:57:01
0B3X9GlR6EmbnOVRQN0t6RkxVQk0 drive-windows-amd64.exe 5 MB 2013-01-01 21:56:41
0B3X9GlR6Embnc1BtVVU1ZHp2UjQ drive-linux-arm 4 MB 2013-01-01 21:57:23
0B3X9GlR6EmbnU0ZnbGV4dlk1T00 drive-linux-amd64 5 MB 2013-01-01 21:55:06
0B3X9GlR6EmbncTk1TXlMdjd1ODQ drive-darwin-amd64 5 MB 2013-01-01 21:53:34
Upload file or directory
$ gdrive upload --file drive-linux-amd64
Id: 0B3X9GlR6EmbnU0ZnbGV4dlk1T00
Title: drive-linux-amd64
Size: 5 MB
Created: 2013-01-01 21:55:06
Modified: 2013-01-01 21:55:06
Md5sum: 334ad48f6e64646071f302275ce19a94
Shared: False
Uploaded 'drive-linux-amd64' at 510 KB/s, total 5 MB
Upload file or directory to a particular folder
$ gdrive upload -p 0B3X9GlR6EmbncTk1TXlMdjd1ODQ --file drive-linux-amd64
Download file
$ gdrive download --id 0B3X9GlR6EmbnenBYSFI4MzN0d2M
Downloaded 'drive-freebsd-amd64' at 2 MB/s, total 5 MB
Share a file
$ gdrive share --id 0B3X9GlR6EmbnOVRQN0t6RkxVQk0
File 'drive-windows-amd64.exe' is now readable by everyone @ https://drive.google.com/uc?id=0B3X9GlR6EmbnOVRQN0t6RkxVQk0
Pipe content directly to your drive
$ echo "Hello World" | gdrive upload --stdin --title hello.txt
Id: 0B3X9GlR6EmbnVHlHZWZCZVJ4eGs
Title: hello.txt
Size: 12 B
Created: 2013-01-01 22:05:44
Modified: 2013-01-01 22:05:43
Md5sum: e59ff97941044f85df5297e1c302d260
Shared: False
Uploaded 'hello.txt' at 6 B/s, total 12 B
Print file to stdout
$ gdrive download --stdout --id 0B3X9GlR6EmbnVHlHZWZCZVJ4eGs
Hello World
Get file info
$ gdrive info --id 0B3X9GlR6EmbnVHlHZWZCZVJ4eGs
Id: 0B3X9GlR6EmbnVHlHZWZCZVJ4eGs
Title: hello.txt
Size: 12 B
Created: 2013-01-01 22:05:44
Modified: 2013-01-01 22:05:43
Md5sum: e59ff97941044f85df5297e1c302d260
Shared: False
Get a url to the file
$ gdrive url --id 0B3X9GlR6EmbnVHlHZWZCZVJ4eGs
https://drive.google.com/uc?id=0B3X9GlR6EmbnVHlHZWZCZVJ4eGs
For more details on script and configuration [perch_button title=”Contact US” size=”small” url=”https://servervendors.com/contact-us/” rel=”none”]Contact Us[/perch_button]