|
| 1 | +# Setup a Google Drive DVC Remote |
| 2 | + |
| 3 | +Follow this guide to setup Google Drive as your <abbr>DVC project</abbr>'s |
| 4 | +[remote storage](/doc/command-reference/remote). |
| 5 | + |
| 6 | +## Configure a Google Cloud project |
| 7 | + |
| 8 | +DVC uses the [Google Drive API](https://developers.google.com/drive) to connect |
| 9 | +to your Google Drive. This requires a Google Cloud _project_ that allows Drive |
| 10 | +API connections, and its |
| 11 | +[OAuth](https://developers.google.com/identity/protocols/OAuth2) credentials |
| 12 | +(**client ID** and **client secret**). |
| 13 | + |
| 14 | +1. Sign into the [Google API Console](https://console.developers.google.com). |
| 15 | + |
| 16 | + > Double check you're using the intended Google account (upper-right corner). |
| 17 | +
|
| 18 | +2. Select or |
| 19 | + [Create](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project) |
| 20 | + a project for DVC remote connections. |
| 21 | + |
| 22 | +3. [Enable the Drive API](https://developers.google.com/drive/api/v2/about-sdk) |
| 23 | + from the **APIs & Services** **Dashboard** (left sidebar), click on **+ |
| 24 | + ENABLE APIS AND SERVICES**. Find and select the "Google Drive API" in the API |
| 25 | + Library, and click on the **ENABLE** button. |
| 26 | + |
| 27 | +  |
| 28 | + |
| 29 | +4. Go back to **APIs & Services** in the left sidebar, and select **OAuth |
| 30 | + consent screen**. Chose a **User Type** and click **CREATE**. On the next |
| 31 | + screen, enter an **Application name** e.g. "DVC remote storage", and click |
| 32 | + the **Save** (scroll to bottom). |
| 33 | + |
| 34 | +5. From the left sidebar, select **Credentials**, and click the **Create |
| 35 | + credentials** dropdown to select **OAuth client ID**. Chose **Other** and |
| 36 | + click **Create** to proceed with a default client name. |
| 37 | + |
| 38 | +  |
| 39 | + |
| 40 | +6. The newly generated **client ID** and **client secret** should be shown to |
| 41 | + you now, and you can always come back to **Credentials** to fetch them. |
| 42 | + |
| 43 | +⚠️ It should be safe to share **client ID** and **client secret** among your |
| 44 | +team. These credentials are only used to generate the |
| 45 | +[authorization](#authorization) DVC will later need in order to connect to the |
| 46 | +Google Drive. |
| 47 | + |
| 48 | +> Note that Google Drive API has usage limits/quotas per credentials in a |
| 49 | +> _project_ (which you can review in the |
| 50 | +> [OAuth consent screen](https://console.developers.google.com/apis/credentials/consent)). |
| 51 | +> Please keep this in mind when sharing them, or you may |
| 52 | +> [exceed the limits](https://developers.google.com/drive/api/v2/handle-errors?hl=ro#resolve_a_403_error_usage_limit_exceeded). |
| 53 | +
|
| 54 | +## URL format for Google Drive remotes |
| 55 | + |
| 56 | +A GDrive DVC remote URLs is needed for the `dvc remote add` command. It can be |
| 57 | +constructed with a _base_, and an **optional** _path_ to a folder i.e. |
| 58 | +`gdrive://<base>/path/to/folder`. The base can be one of: |
| 59 | + |
| 60 | +1. `root` - indicates your topmost Google Drive directory. |
| 61 | + |
| 62 | +```dvc |
| 63 | +$ dvc remote add -d mygdroot gdrive://root |
| 64 | +$ dvc remote add mygdfolder gdrive://root/path/to/folder |
| 65 | +``` |
| 66 | + |
| 67 | +2. Google Drive _Folder ID_ |
| 68 | + |
| 69 | +To obtain the unique _Folder ID_ in question, navigate into that folder in your |
| 70 | +web browser, and find it in the address bar. For example, for |
| 71 | +`https://drive.google.com/drive/folders/0AIac4JZqHhKmUk9PDA`: |
| 72 | + |
| 73 | +```dvc |
| 74 | +$ dvc remote add mygdfolder gdrive://0AIac4JZqHhKmUk9PDA |
| 75 | +$ dvc remote add mygdsubfolder \ |
| 76 | + gdrive://0AIac4JZqHhKmUk9PDA/sub/path |
| 77 | +``` |
| 78 | + |
| 79 | +[Shared drives](https://developers.google.com/drive/api/v2/about-shareddrives) |
| 80 | +should be referenced by _Folder ID_ in the same way. |
| 81 | + |
| 82 | +3. `appDataFolder` - special |
| 83 | + [application-specific data](https://developers.google.com/drive/api/v2/appdata) |
| 84 | + folder only accessible by your application and hidden from the user. |
| 85 | + |
| 86 | +```dvc |
| 87 | +$ dvc remote add mygdappata gdrive://appDataFolder |
| 88 | +``` |
| 89 | + |
| 90 | +## Configure the GDrive remote |
| 91 | + |
| 92 | +Use the `dvc remote modify` command to set the credentials for each `gdrive://` |
| 93 | +remote, for example: |
| 94 | + |
| 95 | +```dvc |
| 96 | +$ dvc remote add -d mygdfolder gdrive://root/path/to/folder |
| 97 | +$ dvc remote modify mygdfolder gdrive_client_id <client ID> |
| 98 | +$ dvc remote modify mygdfolder gdrive_client_secret <client secret> |
| 99 | +``` |
| 100 | + |
| 101 | +## Authorization |
| 102 | + |
| 103 | +On the first usage of a GDrive [DVC remote](/doc/command-reference/remote), |
| 104 | +you'll be prompted to visit a web page to generate an access token, which will |
| 105 | +require you to sign into the corresponding Google account. The |
| 106 | +[sign-in process](https://developers.google.com/drive/api/v2/about-auth) will |
| 107 | +guide you through granting the necessary access permissions. On success, the |
| 108 | +token data will be cached in a Git-ignored directory located in |
| 109 | +`.dvc/tmp/gdrive-user-credentials.json`. |
| 110 | + |
| 111 | +⚠️ In order to prevent unauthenticated access to your Google Drive, **do not |
| 112 | +share access token data with others**. Each team member should have |
| 113 | +[separate access](https://support.google.com/drive/answer/7166529) to the |
| 114 | +appropriate Google Drive resources, and generate their own tokens. |
0 commit comments