There is no official Google drive client for Linux. I tried many different clients found all over GitHub but none of them worked reliably for me except rclone. I also tried third-party proprietary clients like Insync but allowing read-write access to all your Google drive files to a closed source blob is too much to swallow.
Once caveat with rclone
is that it does not natively support bi-directional sync (github issue) but someone developed a python script rclonesync-V2 which is a wrapper around rclone
which does the job. With these two pieces of software we can get close-to-official Google drive client experience.
Install and Setup rclone
-
Install and config rclone google-drive remote
curl https://rclone.org/install.sh | sudo bash rclone config
Just follow rclone prompts to setup a “remote” for your Google Drive account. You can name this remote anything. In my case I simply named it
remote
– this is the remote name I will use in snippets below; adjust accordingly if you name it differently.
Install and setup rclonesync-V2
-
Get
rsyncclone-V2
mkdir ~/src cd ~/src git clone https://github.com/cjnaz/rclonesync-V2.git
-
Do a first-sync
-
Make sure the local path is empty before the first sync otherwise older local files may overwrite newer remote files of the same name on the first sync.
mkdir ~/GDrive python $HOME/src/rclonesync-V2/rclonesync.py ~/GDrive remote:/ --first-sync --rclone-args --drive-export-formats link.html
-
--drive-export-formats link.html
: This flag creates links to google docs instead of trying to convert them to a locally editable or achievable format. For instance, a Google doc namedDMA
would be downloaded asDMA.link.html
which, when opened with chrome, would redirect you to the actual Google doc. This is the same behavior as the official google-drive client on MacOS/Windows.
-
-
Create
~/bin/rclonesync.sh
to manually sync local folder with google drive. You can sync the entire drive or a specific folder. For example, to only sync a folder namednotes
placed in google-drive root, replaceremote:/
withremote:/notes
.#!/bin/bash python $HOME/src/rclonesync-V2/rclonesync.py ~/GDrive remote:/ --rclone-args --drive-export-formats link.html
Schedule periodic syncs using systemd
- Create dir
~/.config/systemd/user
if it does not already exist. - Create file
~/.config/systemd/user/rclonesync.service
[Unit]
Description=rclonesync service
Wants=rclonesync.timer
[Service]
ExecStart=%h/bin/rclonesync.sh
[Install]
WantedBy=default.target
- Create file
~/.config/systemd/user/rclonesync.timer
[Unit]
Description=Run rclonesync every few minutes
[Timer]
OnCalendar=*:0/5
Persistent=true
[Install]
WantedBy=timers.target
- Enable this service
systemctl --user enable --now rclonesync
- To check service status
systemctl --user status rclonesync
- To check when the next sync would occur:
systemctl --user list-timers
Sample output:
NEXT LEFT LAST PASSED UNIT ACTIVATES
Mon 2019-04-22 15:35:00 PDT 3min 31s left Mon 2019-04-22 15:30:34 PDT 54s ago rclonesync.timer rclonesync.service
Sync would now happen every 5 minutes (see OnCalendar=...
in the .timer
file). rclonesync
creates a lock file (/tmp/rclonesync_LOCK
) to make sure there are no concurrent runs. So, if a previously scheduled (or manually run) instance of rclonesync
is running, the lock would prevent any new runs of the same till the previous instance finishes.
Remember that you can still run ~/bin/rclonesync.sh
manually in addition to these scheduled syncs in case you want to push or pull changes immediately.
It’s not a one-click solution like the official client or proprietary clients like InSync
but I think the above setup is more secure and is not too cumbersome to setup.