DriveSync – Easy way to Sync files between local and Google Drive from Linux CLI

Google Drive is an one of the best cloud storage compared with other cloud storage.

It allow users to access the application anywhere irrespective of devices.We can upload, download & share documents, photo, files, docs, spreadsheet, etc to anyone with securely.

We had already written few articles in 2daygeek website about google drive mapping with Linux.

If you would like to check those, navigate to the following link.

GNOME desktop offers easy way to Integrate Google Drive Using Gnome Nautilus File Manager in Linux without headache.

Also, you can give a try with Google Drive Ocamlfuse Client.

What is DriveSync?

DriveSync is a command line utility that synchronizes your files between local system and Google Drive via command line.

Downloads new remote files, uploads new local files to your Drive and deletes or updates files both locally and on Drive if they have changed in one place.

Allows blacklisting or whitelisting of files and folders that should not / should be synced.

It was written in Ruby scripting language so, make sure your system should have ruby installed. If it’s not installed then install it as a prerequisites for DriveSync.

DriveSync Features

  • Downloads new remote files
  • Uploads new local files
  • Delete or Update files in both locally and Drive
  • Allow blacklist to disable sync for files and folders
  • Automate the sync using cronjob
  • Allow us to set file upload/download size (Defautl 512MB)
  • Allow us to modify Timeout threshold

How to install Ruby Scripting language in Linux?

Ruby is an interpreted scripting language for quick and easy object-oriented programming. It has many features to process text files and to do system management tasks (like in Perl). It is simple, straight-forward, and extensible.

It’s available in all the Linux distribution official repository. Hence we can easily install it with help of distribution official Package Manager.

For Fedora system, use DNF Command to install Ruby.

$ sudo dnf install ruby rubygem-bundler

For Debian/Ubuntu systems, use APT-GET Command or APT Command to install Ruby.

$ sudo apt install ruby ruby-bundler

For Arch Linux based systems, use Pacman Command to install Ruby.

$ sudo pacman -S ruby ruby-bundler

For RHEL/CentOS systems, use YUM Command to install Ruby.

$ sudo yum install ruby ruby-bundler

For openSUSE Leap system, use Zypper Command to install Ruby.

$ sudo zypper install ruby ruby-bundler

How to install DriveSync in Linux?

DriveSync installation also easy to do it. Follow the below procedure to get it done.

$ git clone
$ cd drivesync/
$ bundle install

How to set up DriveSync in Linux?

As of now, we had successfully installed DriveSync and still we need to perform few steps to use this.

Run the following command to set up this and Sync the files.

$ ruby drivesync.rb

When you ran the above command you will be getting the below url.

Navigate to the given URL in your preferred Web Browser and follow the instruction. It will open a google sign-in page in default web browser. Enter your credentials then hit Sign in button.

Enter your password.

Hit Allow button to allow DriveSync to access your Google Drive.

Finally, it will give you an authorization code.

Just copy and past it on the terminal and hit Enter button to start the sync.

Yes, it’s syncing the files from Google Drive to my local folder.

$ ruby drivesync.rb
Warning: Could not find config file at /home/daygeek/.drivesync/config.yml . Creating default config...
Open the following URL in the browser and enter the resulting code after authorization
Local folder is 1437 files behind and 0 files ahead of remote
Starting sync at 2019-01-06 19:48:49 +0530
Downloading file ...
Downloading file 5459XXXXXXXXXX25_11-03-2018.PDF ...
Downloading file 2g-image-design/new-design-28-Mar-2018/new-base-format-icon-theme.svg ...
Downloading file 2g-image-design/new-design-28-Mar-2018/2g-banner-format.svg ...
Downloading file 2g-image-design/new-design-28-Mar-2018/new-base-format.svg ...
Downloading file documents/Magesh_Resume_Updated_26_Mar_2018.doc ...
Downloading file documents/Magesh_Resume_updated-new.doc ...
Downloading file documents/Aadhaar-Thanu.PNG ...
Downloading file documents/Aadhaar-Magesh.PNG ...
Downloading file documents/Copy of PP-docs.pdf ...
Downloading file EAadhaar_2189821080299520170807121602_25082017123052_172991.pdf ...
Downloading file Tanisha/VID_20170223_113925.mp4 ...
Downloading file Tanisha/VID_20170224_073234.mp4 ...
Downloading file Tanisha/VID_20170304_170457.mp4 ...
Downloading file Tanisha/IMG_20170225_203243.jpg ...
Downloading file Tanisha/IMG_20170226_123949.jpg ...
Downloading file Tanisha/IMG_20170226_123953.jpg ...
Downloading file Tanisha/IMG_20170304_184227.jpg ...
Sync complete.

It will create the drive folder under /home/user/Documents/ and sync all the files in it.

DriveSync configuration files are located in the following location /home/user/.drivesync/ if you had installed it on your home directory.

$ ls -lh ~/.drivesync/
total 176K
-rw-r--r-- 1 daygeek daygeek 1.9K Jan  6 19:42 config.yml
-rw-r--r-- 1 daygeek daygeek 170K Jan  6 21:31 manifest

You can make your changes by modifying the config.yml file.

How to verify whether Sync is working or Not?

To test this, we are going to create a new folder called 2g-docs-2019. Also, adding an image file in it. Once it’s done, run the drivesync.rb command again.

$ ruby drivesync.rb
Local folder is 0 files behind and 1 files ahead of remote
Starting sync at 2019-01-06 21:59:32 +0530
Uploading file 2g-docs-2019/Asciinema - Record And Share Your Terminal Activity On The Web.png ...

Yes, it has been synced to Google Drive. The same has been verified through Web Browser.

Create the below CronJob to enable an auto sync. The following “CronJob” will be running on every mins.

$ vi crontab
*/1 * * * * ruby ~/drivesync/drivesync.rb

I have added one more file to test this. Yes, it got success.

Jan 07 09:36:01 daygeek-Y700 crond[590]: (daygeek) RELOAD (/var/spool/cron/daygeek)
Jan 07 09:36:01 daygeek-Y700 crond[20942]: pam_unix(crond:session): session opened for user daygeek by (uid=0)
Jan 07 09:36:01 daygeek-Y700 CROND[20943]: (daygeek) CMD (ruby ~/drivesync/drivesync.rb)
Jan 07 09:36:29 daygeek-Y700 CROND[20942]: (daygeek) CMDOUT (Local folder is 0 files behind and 1 files ahead of remote)
Jan 07 09:36:29 daygeek-Y700 CROND[20942]: (daygeek) CMDOUT (Starting sync at 2019-01-07 09:36:26 +0530)
Jan 07 09:36:29 daygeek-Y700 CROND[20942]: (daygeek) CMDOUT (Uploading file 2g-docs-2019/Check CPU And HDD Temperature In Linux.png ...)
Jan 07 09:36:29 daygeek-Y700 CROND[20942]: (daygeek) CMDOUT ()
Jan 07 09:36:29 daygeek-Y700 CROND[20942]: (daygeek) CMDOUT (Sync complete.)
Jan 07 09:36:29 daygeek-Y700 CROND[20942]: pam_unix(crond:session): session closed for user daygeek

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

2 Comments on “DriveSync – Easy way to Sync files between local and Google Drive from Linux CLI”

Leave a Reply

Your email address will not be published. Required fields are marked *