3

I'm having weird stuff happen where my local copy of my Google Drive folders seems out of synchronisation (despite G Drive saying it's sync'd). For example, the folder names are different and changing one doesn't affect the other.

This is 2GB worth of files so I don't want to just download them all to do a 'diff'.

  • Have you restarted Google Drive? It keeps a counter of synced files, and sometimes does not upload changes if the counter hasn't changed. (This does not answer your question, though.) – Christopher Harwood Apr 27 '13 at 18:39
0

The following is a recipe for a comparison based on filenames alone, not based on file modification times or even content checksums. But it's a start :) Also, the below is to compare two directories that are both on Google Drive, but you can easily adapt it by generating a list of your local files instead with some call to ls. (So obviously, the below is a recipe for Linux.)

1. Install and configure drive

drive is a Linux command line client for Google Drive. The easiest is to install it from a package.

After that:

  1. Change into the directory on your computer that includes your whole files synced from Google Drive:

    cd /home/user/example-dir/
    
  2. Initialize drive with access to your Google Drive. This will ask you to visit a URL and paste the auth code you get there, and save this in a config file in the current directory.

    drive init
    

2. Comparing directories

I found that for large Google Drive folders (36 GiB of small files in my case), starting by comparing directories and fixing cases of missing directories was a good first step. (Also because drive has no option to copy directories without the files inside between two Google Drive folders. Not a problem if you compare between local and remote files only.)

drive list -directories -recursive -no-prompt -sort name "source dir" > DirDiff.1-source.txt
drive list -directories -recursive -no-prompt - 

sort name "dest dir" > DirDiff.2-dest.txt

vim -es +"%s/^\/source dir\///g" +"wq" DirDiff.1-source.txt
vim -es +"%s/^\/dest dir\///g" +"wq" DirDiff.2-dest.txt

The drive command obtain lists of directories from Google Drive, and the vim commands remove the differing base directories from each path so that comparison will work properly.

Now to list the directories that are only in the source tree:

comm -23 <(sort < DirDiff.1-source.txt) <(sort < DirDiff.2-dest.txt) > DirDiff.3-missing.txt

And to show the directories that are only in the destination tree:

comm -13 <(sort < DirDiff.1-source.txt) <(sort < DirDiff.2-dest.txt) > DirDiff.4-added.txt

About using comm like this, see here.

3. Comparing files

This works very similar to comparing directory trees:

drive list -recursive -no-prompt -sort name "source dir" > 1-source-files.txt
drive list -recursive -no-prompt -sort name "dest dir" > 2-dest-files.txt

vim -es +"%s/^\/source dir\///g" +"wq" DirDiff.1-source.txt
vim -es +"%s/^\/dest dir\///g" +"wq" DirDiff.2-dest.txt

To show the files only in the source tree:

comm -23 <(sort < FileDiff.1-source.txt) <(sort < FileDiff.2-dest.txt) > FileDiff.3-missing.txt

To show the files only in the destination tree:

comm -13 <(sort < FileDiff.1-source.txt) <(sort < FileDiff.2-dest.txt) > FileDiff.4-added.txt
0

The following improves on my other answer because it allows to compare directories also by modification time and content instead of just the filename. It is also a recipe for Linux.

1. Install and configure drive

drive is a Linux command line client for Google Drive. The easiest is to install it from a package.

After that:

  1. Change into the directory on your computer that includes your whole files synced from Google Drive:

    cd /home/user/example-dir/
    
  2. Initialize drive with access to your Google Drive. This will ask you to visit a URL and paste the auth code you get there, and save this in a config file in the current directory.

    drive init
    

2. Compare the directories

According to the drive documentation for Diffing, you can do the following to compare local and remote directory trees based on file names, modification times and content checksums:

drive diff dir_name

And the following to compare only based on file names and modificatio times:

drive diff -skip-content-check dir_name

Also, an alternative method to only compare based on content checksums is shown in section Retrieving MD5 Checksums:

diff <(drive md5sum) <(md5sum *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.