Google-drive – Move large folder from personal Google Drive to a Team Drive

google-drivegoogle-shared-drive

My place of work uses G Suite apps. For the past five years I have shared with my team a Google Drive folder, which we have maintained as if belonging to the team. I'd like to migrate the contents of this folder to a new Team Drive.

The difficulty I'm encountering is that folders can't be moved from a user's Google Drive to a Team Drive. I can create folders on the Team Drive, and move documents from the shared folder to the Drive, but this process doesn't scale to large folders. One of the folders I need to move contains almost 1800 subfolders.

I tried some other workarounds. For instance, I use Google Drive File Stream, which mounts the drives on my Mac's file system. I tried compressing folders, moving them to the Team Drive, then uncompressing. But the uncompressing job failed.

I also tried using Terminal and mkdir to create folders on the Team Drive, then cp to copy documents. I was hoping I could script a process that descended into the folder's tree of subfolders, created the directories it needed to, and copied over the files. It seems that mkdir works but cp doesn't, even on documents.

I did some web searching but I couldn't find any software that worked copying folders of this size from a personal Google Drive to a Team Drive. Any ideas?

Best Answer

We had a very similar issue. What worked for us was to use the Linux based command-line tool drive.

Preparations

  1. Add your non-GSuite folder as shared folder to your Team Drive. This is needed so that drive can copy files remote-to-remote. Otherwise, Google Docs / Sheets / Draw / Impress files could not be preserved as they are but would have to be exported and re-imported, which can mess them up. And I propose you copy them instead of moving them, because that will make your GSuite account their owner. Otherwise, the origial owners could still change and delete them from the Team Drive.

  2. Install and initialize drive. Means, run drive init to give it access to your Team Drive.

First Approach

Simply copy the files recursively:

    drive copy -recursive old_dir new_dir

Here, old_dir will be the directory where the original Google Drive folder is available as a shared folder in the Team Drive. new_dir will be a newly created subfolder on the Team Drive.

The issue with this approach is that drive is not totally reliable and will sometimes miss on some files and directories due to API errors, or in one case I had hang for hours without making any more progress. So I highly recommend to compare your Google Drive folders afterwards to make sure nothing is missing.

Second Approach

As an alternative method that will show the progress in the command's output (rather than printing only errors as the above), you could use the following approach.

Of course, you can package this nicely as a shell script … I'll only show the general process here step by step:

  1. Create a list of the directories to copy, and remove the source_dir prefix directory by which source and destination paths differ:

    drive list -quiet -recursive -directories 2>&1 | tee -a dirs.txt
    vim -es +"%s/^\/source_dir\///g" +"wq" dirs.txt
    
  2. Go through that list and create all these folders in the corresponding destination directory:

    mapfile -t filenames < dirs.txt;
    for each in "${filenames[@]}"; do echo "creating dir $each …"; drive new -folder "dest_dir/$each" 2>&1 | tee -a dirslog.txt; done;
    
  3. Create a list of the files to copy, and remove the source_dir prefix directory by which source and destination paths differ:

    drive list -quiet -recursive -files 2>&1 | tee -a files.txt
    vim -es +"%s/^\/source_dir\///g" +"wq" files.txt
    
  4. Copy the files one by one and log the progress and result:

    mapfile -t filenames < files.txt;
    for each in "${filenames[@]}"; do echo "copying $each …"; drive copy  "source_dir/$each" "dest_dir/$each" 2>&1 | tee -a fileslog.txt; done;
    
  5. Take the errors from the log file and resolve them manually, or by compiling a list similar to the above and letting the software go through it again.

  6. Again, compare your Google Drive folders to be extra sure that all files made it across.