Categories


Authors

How to Sync Google Drive & OneDrive

How to Sync Google Drive & OneDrive

Google+Drive+OneDrive+Sync.png

As you can tell by my blog posts, I am a huge fan of Google Workspace. In fact, back in 2016, I blogged about the advantages of Google Workspace vs. Microsoft 365. When I joined LT Trust, we were a small company with little appetite for a major culture shift to Google Workspace. When the pandemic rolled around, we had to step up our collaboration game, but we had to do so quickly and smoothly. The early days of the pandemic were definitely not a good time to disrupt the company with a transition to Google Workspace. Therefore, we rolled with Microsoft 365 as our productivity and collaboration suite.

So what’s a Google guy to do in a Microsoft malaise? Improvise. I still use Google Drive and its associated apps, but now I also use a script to sync my changes to OneDrive. I created the script myself instead of using a cloud-based service. Zapier’s integration might have met my needs, but I didn’t want to introduce a potential security vulnerability. Zapier is reputable, but why introduce a threat vector when you don’t have to?

My Mac-specific solution relies on the following components:

  1. The Google Drive File Stream app

  2. The OneDrive app

  3. The fswatch package (brew install fswatch)

  4. A sync script

  5. A wrapper script

The Sync Script

For the sync script, I used the logic from this Stack Overflow post. The sync script is as follows:

#!/bin/zsh

src="$"
dest="$"

# From: https://stackoverflow.com/questions/34575374/how-to-use-fswatch-and-rsync-to-automatically-sync-directories
alias run_rsync='rsync --archive --verbose --recursive --update --times "$" "$"'
run_rsync; fswatch -o $ | while read f; do run_rsync; done

For the wrapper script, I created one for syncing Google Drive to OneDrive and another for synching OneDrive to Google Drive. I typically only run the former, but if I am collaborating with others, I might run them both. Just modify the following scripts with your specific file paths and whatever you named your sync script (I named mine myrsync.sh).

Google Drive-to-OneDrive Script

#!/bin/zsh

/Users/username/gdrive/dev/myrsync.sh "/Volumes/GoogleDrive/Shared drives/To365/Technology - Documents/General/FromGSuite" "/Users/username/LT Trust-OneDrive/LT Trust/Technology - Documents/General" > /Users/username/gdrive/dev/myrsync.gd-to-365.log 2>&1 &

OneDrive-to-Google Drive Script

#!/bin/zsh

/Users/username/gdrive/dev/myrsync.sh "/Users/username/LT Trust/Technology - Documents/General/FromGSuite" "/Volumes/GoogleDrive/Shared drives/To365/Technology - Documents/General" > /Users/username/gdrive/dev/myrsync.365-to-gd.log 2>&1 &

Procedure

Lastly, here are the procedural steps I take when I am working on a new file. Note that other than running the sync script, editing existing files do not require these steps. The following steps use a spreadsheet as an example, but the same steps work for other file types too.

  1. In Google Drive, create a new Google Sheet in the root of “My Drive”.

  2. Make some initial changes and name the Google Sheet.

  3. Download it as an Excel file: File > Download > Microsoft Excel (.xslx).

  4. Start the “Google Drive-to-OneDrive Script“ script.

  5. In Google Drive, upload the Excel file to the synced folder - in my case, /Volumes/GoogleDrive/Shared drives/To365/Technology - Documents/General/FromGSuite.

  6. Continue editing the Excel file in Google Sheets.

Java & C++ Guide

Java & C++ Guide

Low-code Case Study with Salesforce

Low-code Case Study with Salesforce