Using OneDrive for Business to Sync Large Volumes of Data

Do you use Office 365? If you do, you can also use 1TB cloud storage at no additional cost, courtesy of OneDrive for Business. This gives Microsoft a leg up on competitors: Dropbox, Box Sync, Google Drive, iCloud, etc. As we learned during the First Browser War (IE vs Netscape Navigator), it’s hard for a paid product to compete with a free one. On the other hand, OneDrive places a lot of restrictions on file names, file path lengths and so on and might be a bit hard around the edges as of this writing (February 2017). Nevertheless, why not give it a shot?

I took a plunge on my Mac, put about 150 GB of data into OneDrive on Office 365 and has been syncing it for several months. The road was bumpy, to say the least, but in the end, I could resolve all the issues I faced so far.

Here is what I learned. (These tips apply to macOS or Windows. Included scripts are Bash scripts for Mac, but they could be potentially ported to PowerShell for Windows.)

The information below applies to syncing your local files to OneDrive cloud and between computers. If you need to sync existing (e.g. on premises) SharePoint libraries, you would face additional restrictions.

Tip 1. Scan your files and folders for long path names.

File path length restriction: The entire path, including the file name, must contain fewer than 255 characters.

Long file paths were immediately killing my OneDrive client (with a pop-up dialog message). They were fatal.

You can scan for these problems before putting your files into OneDrive (see shell script in the Tip 2 section). Once you identify long file paths, shorten your folder structure or archive files as necessary.

Tip 2. Scan your files and folder names for problematic characters.

OneDrive on Office 365 does not sync files or folders that:

(BTW, practically all characters are allowed in macOS filenames except ‘/’ at the Unix layer. ‘:’ is not allowed at the Carbon layer, but it is possible to create filenames with ‘:’.)

The problematic files or folders can’t be synced and manifest themselves as sync errors (that is as those badges with numbers on a OneDrive Dock icon on Mac). If you have many of them, they could cause other issues, for example, an unresponsive OneDrive client:

1-onedrive-busy

Or very wide OneDrive UI windows:

2 - OneDrive - Very Wide Window.png

Here is the combined shell script to detect Tip 1 and Tip 2 problems:

#!/usr/bin/env bash
#set -x
if [[ "$1" == "-h" ]]; then
exec 1>&2
cat << EOF
Finds files and directories in OneDrive that are invalid to sync

Practically all characters are allowed in macOS filenames except / at the Unix layer.
: is not allowed at the Carbon layer, but it is possible to create filenames with :. See http://superuser.com/questions/326103/what-are-invalid-characters-for-a-file-name-under-os-x and https://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations.

OneDrive does not sync files or folders that:
* Include any of the following characters: \#%:"|?*/
* Begin or end with a space
* End with .
* Begin with ..
* Have very long pathnames (>= 255 characters)

Usage: $0 [-h]

Parameters:
-h Help
Notes:
Ignores unreachable directories (and other errors)

Examples:
$0
EOF
exit 127
fi

# Comment out the following line to search prior to putting files into OneDrive
cd ~/OneDrive*
echo "Searching for files and directories that are invalid to sync in $PWD..."
echo

find -E . -regex '(.*[\#%:"|?*].*)|.{255,}' -or -name ' *' -or -name '* ' -or -name '?*.' -or -name '..*' 2>/dev/null
# -regex pattern is true if the whole path of the file matches pattern.
# For example: to match a file named `./foo/xyzzy`, you can use the regular expression `.∗/[xyz]∗` or `.∗/foo/.∗`, but not `xyzzy` or `/foo/`.
#
# -name '*/*' could be added to test for filenames including /, but those are illegal in macOS.
#
# \ (backslash) inside a pattern character class is used as escape only when followed by any of these: ^-]\
#
# '?*.' glob pattern prevents the root directory (.) from matching

echo "Done."

Once you identify problematic names, you have several choices on how to resolve them:

  1. Rename
  2. Archive (into ZIP, RAR, etc.)
  3. Move out of OneDrive
  4. Delete if not needed.

Tip 3. Watch for sync conflicts.

If you sync among two or more computers, be prepared for conflicts to occur sooner or later. A conflict is a situation where OneDrive can’t decide on the definitive version of a file to use. In this case it’d silently create the second file in the same directory using naming convention {original name}-{computer name}.{original extension}. Often file contents would be the same, but to avoid any data or storage loss you need to detect and manually resolve these conflicts.

The following shell script watches for conflicts in real time. When a conflict is found, the script logs the conflict and notifies via Growl. This script is designed to run in the background. You can launch it when your computer starts, e.g. using Login Items or launchd:

#!/usr/bin/env bash
#set -x
exec 1>>~/Library/Logs/conflict-watches.log 2>>~/Library/Logs/conflict-watches.log
echo "`date` conflict-watch-onedrive> Starting ..."

watchedPath=~/OneDrive*

# Base file name marker, e.g. "Communications-MyComputer.msf" or "Communications-MyComputer"
conflictMarker=-`hostname -s`

echo "`date` conflict-watch-onedrive> Watching" $watchedPath/ "..."

# Enters the waiting loop
# Includes only Created and Renamed (= moved) events. Deletions, updates and other events are ignored.
fswatch -r0 --event Created --event Renamed -e ".*" -i "$conflictMarker" $watchedPath | while read -d "" filename
do
echo "`date` OneDrive conflict: $filename"
growlnotify "OneDrive conflict" -m "$filename"
done

Tip 4. Reboot less often.

After OneDrive starts, it takes at least hours on my machine to finish scanning of about 150 GB of data. During all that time OneDrive consumes about 100% of one core’s CPU:

3-onedrive-cpu-load

Temperature goes up and fans spin all that time.

To avoid this, I changed my habits and stopped shutting down my laptop daily.

Tip 5. Sync only what needs to be synced. Don’t sync large, frequently changed files.

If your data already lives on some servers and get synced among your devices, you don’t need to put it into OneDrive. For example, corporate Exchange email is stored on Exchange servers and any changes in it get automatically synced among Outlook clients. On the other hand, personal Outlook archives might be locally stored files, which you might want to put into OneDrive.

I have private email stored in a Mozilla Thunderbird profile, in a combination of Thunderbird IMAP and POP mailboxes and email archives. I tried to put the entire profile into OneDrive to sync all email along with all the Thunderbird settings. It turned out to be a bad idea because of a way Thunderbird stores and caches mail. Even for IMAP mailboxes, I have, for example, 1.7 GB (after compacting) GMail All Mail folder, which is stored in a single file.

In OneDrive for Business, unlimited versioning is usually turned on by default (this might depend on how your IT administrators configured your Office365 Sharepoint). Unlike, for example Dropbox, previous versions in OneDrive consume storage and count towards 1TB storage limit.

Frequent updates in 1.7 GB and my other large mailbox folders were stored as separate versions and they quickly consumed all 1 TB of OneDrive space. The solution for this issue was to move Thunderbird profile out of OneDrive and sync it by other means.

Tip 6. Watch for phantom syncs.

A couple of my files caused OneDrive to never finish: files were always shown in the process of being synced, e.g.:

4-onedrive-phantom-download

Earlier versions of OneDrive client didn’t have a detail progress window to see what’s going on. After the progress window had been added in the later versions I was able to catch onto these phantoms and dig deeper. It turns out that OneDrive server was showing some sort of virus problem in a couple of my old mailbox folders and that’s probably why phantoms were occurring. Once I removed offending files, the problem was resolved.

And here it is: a successfully synced OneDrive.

5-onedrive-success

2017 March 29 Update: conflict-watch-onedrive.sh script has been updated to respond only to Created and Renamed events.

The Quest for Great Coffee: Kiev

Recently I was in Kiev on a vacation and, taking advantage of an occasion, explored its vibrant coffee scene. Years ago (think former Soviet Union time), Kiev had several great cafés making decent espresso, Turkish coffee, drinking chocolate, etc.

Nowadays, the scene is a mixture of numerous shops of several competing espresso chains, individual specialized coffeehouses, restaurants and even mobile “espresso trucks”:

The competition, especially in the downtown, is fierce. I notice one small single building (Chervonoarmiis’ka St, 48) that had 3 different shops.

My project was to find high-end shops that make a great “wet” cappuccino. After some initial Internet research, I ended up with a list of 11 shops. I tried cappuccino in all of these shops and also tried food in most. The prices for a small cappuccino varied roughly from US $1.5 to US $6.

I graded them on the scale of 1 to 5. Note: I am not a professional master taster; I am just a coffee lover with a passion for a great cappuccino. I’m not affiliated in any way with any of these shops.

Coffeeshop Kiev’s Location Seating / Décor WiFi Food Cappuccino

Espreso Kіmnata (Еспресо Кімната)

Khreshchatyk St, 40/1 (вул. Xрещатик, 40/1)

2 No N/A 3

Kofe Khauz (Кофе Хауз)

Velyka Zhytomyrs’ka St, 8/14 (Велика Житомирська вул., 8/14) + 27 locations

4 No (?) 5- 4-

Dom Kofe “Olympyyskyy” (Дом Кофе “Олимпийский”)

Chervonoarmiis’ka St, 72 (Червоноармійська вул., 72)

3 No N/A 5

Espressamente Illy at Arena

Baseina St, 2a, Arena, 2nd floor

(Басейна вул., 2а, Арена, 2й поверх)

3 Yes 4 3+

Restoran “Bel’veder” (Ресторан “Бельведер”)

Dniprovs’kyi descent, 1 (Дніпровський узвіз, 1)

5+ Yes N/A 3

boutiquebar Biancoro

Baseina St, 4 (Басейна вул., 4)

4 Yes N/A 3+

Aroma Espresso Bar KIEV

Dymytrova St, 5 (вул. Димитрова, 5)+ 2 other locations

5 No (?) 3+ 3+

Golden Ducat (Золотий дукат)

Chervonoarmiis’ka St, 48 (Червоноармійська вул., 48); Instytuts’ka St, 16 (вул. Інститутська, 16) + 1 other location

5+ No (?) 4+ 3

Coffee Life

Maidan Nezalezhnosti, 2 (майдан Незалежності, 2) + 5 other locations

5 Yes 5 3+

Kaffa (“Каффа” на Подоле)

Hryhoriya Skovorody St, 5 (вул. Григорія Сковороди, 5)

5 No (?) N/A 2

Double Coffee

Mykhailivs’ka St, 8а (Михайлівська вул., 8а) + 7 other locations

5 Yes 5+ 3+

Most of these shops do make “wet” cappuccino, but their quality can be improved. Often, the taste is not bitter, as in a bad espresso, but rather stale or harsh. Still, most of them do a better job than Starbucks. Starbucks would get a grade of 2 to 3- on my scale.

The clear winner for me is Dom Kofe “Olympyyskyy” (Дом Кофе “Олимпийский”). It’s a very small shop, but it makes a great cappuccino and offers a selection of beans for your espresso drinks.

Automate your Feature and Acceptance Tests in Four Easy Steps

Any significant web application at some point faces the question of how to approach testing of user-facing functionality. Developers could be (hopefully) happily churning out their JUnit-s, NUnit-s and Test::Unit-s, practicing TDD and Continuous Integration, but what does testing your classes, methods, and functions have to do with what your customers actually need from your system?

The answer is: not much, really. Testing web application from the end-user perspective involves dealing with test cases written in a business language, and secondly, firing multiple browsers and hunting down why this particular feature works perfectly fine in a browser Foo and does not work at all in a browser Baz. The right tools for automating this process are Behavior-Driven Development tools and browser “drivers”. These tools come from different development worlds and communities: Ruby, .NET, Java.

Fortunately, you can use many of these tools to test any web application regardless of your application platform whether it’s JavaEE, .NET, ColdFusion, PHP or Ruby on Rails. The tools came the long way since early days of Fit/Fitnesse and you can get from zero feature tests to automation in few easy steps using any desktop OS: Windows, Mac OS X or Linux. I promise.

What might be the most difficult part of this process is bewildering number of choices to make. A lot of choice is a Good Thing and all the tools mentioned in this post are free, open-source tools, but how it all fits together could be quite confusing. Fear not. Let’s walk through the steps.

Step 1. Select and Install a BDD Tool

Behavior-Driven Development is taking automated unit testing a level higher. The emphasis is on a language and readability of tests (or rather scenarios, broken down to steps in BDD parlance). One of the most active communities championing BDD tools is Ruby world. The framework that generated a lot of buzz in the last couple of years is Cucumber. It is a flexible Ruby framework that uses a wonderful domain-specific language for writing your scenarios: Gherkin. Gherkin is pretty much structured English or one of 37 other supported spoken languages. Cucumber natively uses Ruby for glue code (step definitions) that ties your features, scenarios and steps to browser drivers (or to native target applications).

Now, if you don’t know Ruby you might be tempted to go with one of Cucumber ports, for example cucumber-jvm (Java) or SpecFlow (.NET). You would get to write glue code in your programming language of choice, but the setup if often more complex, ports could be less mature or lagging behind flagship Ruby tools. It is hard to come up with other benefits of ports for testing web applications. Why not use this opportunity and learn a fun dynamic language with a lot of interesting ideas? It is used as the first language to teach kids, after all, and you don’t have to learn Rails and a lot of other Ruby frameworks, just the language itself.

My choice: Cucumber

Other choices: Fit/Fitnesse, SpecFlow, RSpec, easyb, etc.

What to do:

  • Windows: Install Ruby 1.8.x and add it to the PATH. Latest versions of Mac OS X come with Ruby 1.8.x. Don’t use Ruby 1.9.x just yet (see below).
  • Set RUBYOPT=-rubygems in your environment.
  • Go to your command line and install the Cucumber Ruby gem.
    >gem install cucumber

    Note: Any gem installation might fail with the following:
    ERROR: http://rubygems.org/ does not appear to be a repository
    This problem is transient. Try again in 5 minutes. Another option is to download needed .gem manually and install it:

    >cd {download directory}
    >gem install -lV cucumber

    The local installation (-l) will install Gem dependencies only if they are available in the Gem caches or in the local directory. You might need to download dependencies manually as well.

  • Windows: (optional, but highly recommended in order to display colored output) Install ANSICON.
  • Install RSpec for writing assertions in your glue code.
    >gem install rspec