
# Google Drive

Google Drive is a widely used cloud storage service provided by Google, offering
users the ability to store files, share documents, and collaborate in real time.

[Rclone](https://rclone.org/) is a command-line program to manage files on cloud
storage, and supports Google Drive as one of its many backends.

The Rclone integration package for Plakar provides three connectors:

| Connector type            | Description                                            |
| ------------------------- | ------------------------------------------------------ |
| **Storage connector**     | Host a Kloset store inside a Rclone remote.            |
| **Source connector**      | Back up a Rclone remote into a Kloset store.           |
| **Destination connector** | Restore data from a Kloset store into a Rclone remote. |

**Requirements**

- Rclone must be installed, and at least one Google Drive remote must be
  configured.

**Typical use cases**

- Cold backup of Google Drive folders
- Long-term archiving and disaster recovery
- Portable export and vendor escape to other platforms

## Installation

To interact with Google Drive, you need to install the Rclone Plakar package.

{{< tabs >}}

{{< tab label="Pre-built package" >}}

Pre-compiled packages are available for common platforms and provide the
simplest installation method.

> [!NOTE]+ Logging In Pre-built packages require Plakar authentication. See
> [Logging in to Plakar](../../guides/logging-in-to-plakar) for details.

Install the Rclone package:

```bash
$ plakar pkg add rclone
```

Verify installation:

```bash
$ plakar pkg list
```

{{< /tab >}}

{{< tab label="Building from source" >}}

Source builds are useful when pre-built packages are unavailable or when
customization is required.

**Prerequisites:**

- Go toolchain compatible with your **Plakar** version

Build the package:

```bash
$ plakar pkg build rclone
```

A package archive will be created in the current directory (e.g.,
`rclone_v1.0.0_darwin_arm64.ptar`).

Install the package:

```bash
$ plakar pkg add ./rclone_v1.0.0_darwin_arm64.ptar
```

Verify installation:

```bash
$ plakar pkg list
```

{{< /tab >}}

{{< /tabs >}}

To list, upgrade, or remove the package, see
[managing packages guide](../../guides/managing-packages/).

## Generate Rclone configuration

Install Rclone on your system by following the instructions at
[https://rclone.org/install/](https://rclone.org/install/).

Then, run the following command to configure Rclone with Google Drive:

```bash
$ rclone config
```

You will be guided through a series of prompts to set up a new remote for Google
Drive.

For Rclone v1.72.1, the configuration flow is as follows:

1. Choose `n` to create a new remote.
2. Name the remote (e.g., `mydrive`).
3. Enter the number corresponding to "Google Drive" from the list of supported
   storage providers.
4. Leave `client_id` and `client_secret` empty to use Rclone's defaults, or
   provide your own if you have them.
5. Select the number corresponding to "Full access all files, excluding
   Application Data Folder.", or to "Read-only access to file metadata and file
   contents." if you only need read access.
6. Leave the service account file empty unless you have one.
7. When prompted about advanced config, choose to edit it and set
   `root_folder_id` to a specific subfolder (recommended, see note below). This
   keeps all Plakar data in one place and avoids cluttering the root of your
   drive. If you don't want to use a subfolder, skip to step 8 and stay with the
   current settings.
8. Choose to open the browser for authentication.
9. Set whether to use a shared drive or not depending on your needs.
10. Validate the remote configuration.

> [!NOTE]+ Using a subfolder (recommended)
>
> Restricting Rclone to a dedicated subfolder keeps your Google Drive organised
> and makes it easy to identify Plakar data at a glance.
>
> 1. Create a folder in the Google Drive web UI.
> 2. Open the folder. The URL will contain the folder ID, e.g.
>    `https://drive.google.com/drive/folders/<FOLDER_ID>`.
> 3. When prompted at step 7, choose to edit advanced config and set
>    `root_folder_id` to that ID.
>
> Rclone will then treat that folder as its root, and all Plakar data will be
> written there instead of at the top level of your drive.

To verify that the remote is configured, run:

```bash
$ rclone config show mydrive
```

And to verify you have access to your Google Drive files, run:

```bash
$ rclone ls mydrive:
```

The output should list the files and folders in your Google Drive.

## Connectors

The Rclone package provides storage, source, and destination connectors to
interact with Google Drive via Rclone.

You can use any combination of these connectors together with other supported
Plakar connectors.

### Storage connector

The Plakar Rclone package provides a storage connector to host Kloset stores on
Rclone remotes.

<!-- prettier-ignore-start -->
{{< mermaid >}}
flowchart LR

Source["Source data"]

Plakar["Plakar"]

Via["Store snapshot via<br/>Rclone storage connector"]

subgraph Store["Rclone Remote"]
  Kloset["Kloset Store"]
end

Source --> Plakar --> Via --> Kloset
{{< /mermaid >}}
<!-- prettier-ignore-end -->

#### Configure

```bash
# Import the rclone configuration as a storage configuration.
# Replace "mydrive" with your Rclone remote name.
$ rclone config show | plakar store import -rclone mydrive

# Initialize the Kloset store
$ plakar at "@mydrive" create

# List snapshots in the Kloset store
$ plakar at "@mydrive" ls

# Verify integrity of the Kloset store
$ plakar at "@mydrive" check

# Back up a local folder to the Kloset store
$ plakar at "@mydrive" backup /etc

# Back up a source configured in Plakar to the Kloset store
$ plakar at "@mydrive" backup "@my_source"
```

#### Options

These options can be set when configuring the storage connector with
`plakar store add` or `plakar store set`:

| Option       | Purpose                     |
| ------------ | --------------------------- |
| `passphrase` | The Kloset store passphrase |

### Source connector

The Plakar Rclone package provides a source connector to back up remote
directories accessible via Rclone.

<!-- prettier-ignore-start -->
{{< mermaid >}}
flowchart LR

subgraph Source["Rclone Remote"]
  FS["Data"]
end

Plakar["Plakar"]

Via["Retrieve data via<br/>Rclone source connector"]

Store["Kloset Store"]

FS --> Via --> Plakar --> Store
{{< /mermaid >}}
<!-- prettier-ignore-end -->

#### Configure

```bash
# Import the rclone configuration as a source configuration.
# Replace "mydrive" with your Rclone remote name.
$ rclone config show | plakar source import -rclone mydrive

# Back up the remote directory to the Kloset store on the filesystem
$ plakar at /var/backups backup "@mydrive"

# Or back up the remote directory to a Kloset store configured with "plakar store add"
$ plakar at "@store" backup "@mydrive"
```

#### Options

The Rclone source connector doesn't support any specific options.

### Destination connector

The Rclone package provides a destination connector to restore snapshots to
remote directories reachable over Rclone.

<!-- prettier-ignore-start -->
{{< mermaid >}}
flowchart LR

Store["Kloset Store"]

Plakar["Plakar"]

Via["Push data via<br/>Rclone destination connector"]

subgraph Destination["Rclone Remote"]
  FS["Data"]
end

Store --> Plakar --> Via --> FS
{{< /mermaid >}}
<!-- prettier-ignore-end -->

#### Configure

```bash
# Import the rclone configuration as a destination configuration.
# Replace "mydrive" with your Rclone remote name.
$ rclone config show | plakar destination import -rclone mydrive

# Restore a snapshot from a filesystem-hosted Kloset store to the Rclone remote
$ plakar at /var/backups restore -to "@mydrive" <snapshot_id>

# Or restore a snapshot from the Kloset store configured with "plakar store add store …"
$ plakar at "@store" restore -to "@mydrive" <snapshot_id>
```

#### Options

The Rclone destination connector doesn't support any specific options.

## Limitations and considerations

- Google Drive API has rate limits, heavy usage may require throttling.
- File version history is not preserved. Only the current version of each file
  is snapshotted.
- Shared links and permissions are not preserved in snapshots.

## See also

- [Rclone documentation for Google Drive](https://rclone.org/drive/)

