Life2go.net

Mobile technology should not be about cramming the office into your pocket but a way to enjoy your everyday life.

Using Google Drive to sync content on one or more RetroPie/Raspberry Pi

18-NOV-2016

If you are running RetroPie on Raspberry Pi to play retro games you have probably spent more time setting it up and configuring it than actually playing. And if you have two or more...

Wouldn't it be nice to manage the roms folder on a Google Drive folder and let it sync to one or more RetroPies? And if you spent time scraping metadata and box art on one RetroPie that would sync to the others without additional work.

It's kind of possible. But it is slow and you will have to initialize the syncing and choose sync direction manually.

Please note: this might not be the best way to do it. It might not even be a good way to do it. In fact, this might be a horrible way to do it and you may loose all your data and lots of sleep so do it at your own risk and make backups of everything.

You'll need the semi-official Google Drive application for Raspian and you'll find it here:

https://github.com/odeke-em/drive

First, log in to your RetroPie using SSH and create a directory for Google drive and inside that the folder we wish to sync. I created a folder called "drive" and inside that "RetroSync". We want to keep everything here inside one folder and not sync the entire Google Drive.

$ mkdir /home/pi/drive
$ mkdir /home/pi/drive/RetroSync

Then you need to check what version of the drive binary you need by running:

$ cat /proc/cpuinfo | grep "model name"

In my case, running a Raspberry Pi 3, it's ARM v7 - and it will tell you so four times, probably because there are four cores in the CPU.

You can find the URL's to the different version at:

https://github.com/odeke-em/drive/releases/

Copy the right URL and download it with wget. In my case it looks like this:

$ sudo wget https://github.com/odeke-em/drive/releases/download/v0.3.8/drive_armv7 -O /usr/local/bin/drive

That will download the binary file into an application called "drive" located in /usr/local/bin.

Before you can run it though, you need to tell the operating system it is an executable binary:

$ sudo chmod +x /usr/local/bin/drive

Once you'we done that, you can run the command and the first time you need to initialize it by telling drive where your sync folder is (the one we created previously):

$ drive init /home/pi/drive 

When you initialize drive, it will give you a rather long URL beginning with accounts.google.com. Copy the entire URL and paste it into a browser (typically on another computer) where you are logged in as the Google user who's account you wish to use. You will be asked if you wish to grant the application "drive" access to your Google Drive - and if you select yes, you get a key string that you need to copy and paste back into your Raspberry Pi (it will be asking for the verification code).

Now Google Drive is ready to be used on your Raspberry Pi.

But now you have to move the stuff you want to sync into the sync folder. Instead of actually moving files and messing up RetroPie, we create symbolic links in our RetroSync folder to the folders with the content we wish to sync:

The most important folder is the RetroPie folder containing roms and bios files so let's make a link to that:

$ ln -s /home/pi/RetroPie/ /home/pi/drive/RetroSync/RetroPie

But this only syncs the roms. If you have spent a lot of time getting metadata and boxart, that has to be synced as well and that stuff is in two other directories (box art and metadata such as descriptions).

$ ln -s /opt/retropie/configs/all/emulationstation/downloaded_images/ /home/pi/drive/RetroSync/downloaded_images


$ ln -s /opt/retropie/configs/all/emulationstation/gamelists/ /home/pi/drive/RetroSync/gamelists

And now we are ready to sync.

You'll need to move into the sync directory to sync:

$ cd /home/pi/drive

and then you will need to either upload (push) your stuff to Google Drive if you are using a RetroPie with data or download (pull) if you are setting up a new empty RetroPie by running

$ drive pull RetroSync

or

$ drive push RetroSync

The application "drive" will analyze the environment, list what files are going to go where and ask for confirmation (upper case "Y" or lower case "n").

Then you just have to wait a few hours. The first sync is slow but after that only changes are copied and that is much faster.