Operate

Google Drive Sync (Service Account)

Quick Answer

Use this guide to run and operate the Google Drive service-account sync flow, including configuration, schedule behavior, and verification.

This guide covers a production flow that continuously syncs files from a Google Drive folder into Breyta blob storage, and writes per-file metadata docs (KV-backed-by-Firestore) for querying.

Why service account auth (not user OAuth)

Google OAuth user auth is not suitable for continuous, unattended syncing (e.g. every 2 hours), because it requires the user to re-authenticate periodically. For this integration we use a Google service account (SA) so the flow can mint OAuth access tokens on a schedule without user interaction.

Flow + schedule

ItemValue
Flow sluggoogle-drive-folder-sync
TriggerSchedule every 2 hours (cron: 0 */2 * * *, timezone: UTC)
Folder inputDrive folder URL or raw folder id
Archive slot:archive (:blob-storage)

Required secret

The flow uses :auth {:type :google-service-account ...} on :http steps.

Secret settingValue
Secret slot / refgoogle-drive-service-account
Secret valueFull JSON service account key payload

Configure it on the draft target:

StepAction
1Save service account JSON to ./secrets/google-drive-sa.json (local only; do not commit).
2breyta flows configure google-drive-folder-sync --set google-drive-service-account.secret=@./secrets/google-drive-sa.json
3breyta flows run google-drive-folder-sync --input '{"folder":"https://drive.google.com/drive/folders/<id>?usp=sharing","cursor_key":"google-drive-sync:cursor"}' --wait --pretty

Required storage setup

The flow also declares a blob-storage slot :archive.
That slot always requires the installer to choose a storage root.

Recommended setup values:

SettingExample
Connection bindingplatform
Storage rootgdrive

If you change the storage root, persisted files and runtime resource pickers both move to that new storage location automatically.

Run now (manual)

Incremental run (uses the shared cursor)

This is the safest way to “run now”, because it uses the same cursor the schedule uses.

breyta flows run \
  google-drive-folder-sync \
  --input '{"folder":"https://drive.google.com/drive/folders/<id>?usp=sharing","cursor_key":"google-drive-sync:cursor"}' \
  --wait --pretty

Isolated/forced scan (separate cursor)

Use a unique cursor_key to force a “fresh” scan without disturbing the schedule cursor.

breyta flows run \
  google-drive-folder-sync \
  --input '{"folder":"https://drive.google.com/drive/folders/<id>?usp=sharing","cursor_key":"google-drive-sync:cursor:manual-check:20260101T000000Z"}' \
  --wait --pretty

Notes:

ModeWhen to useCursor behavior
Incremental runSafe manual run aligned with schedule stateUses shared cursor (google-drive-sync:cursor)
Isolated/forced scanOne-off fresh scan without affecting schedule cursorUses unique cursor_key
NoteGuidance
Singleton flow run idsRepeated manual starts may reuse stable workflow id; verify by timestamps in runs list/runs show.
--installation-id on manual runsAvoid unless you explicitly need a specific installation target KV namespace.

What gets written

Blobs

Downloads are persisted through the :archive slot.
The slot contributes the configured storage root, and the step contributes the folder id:

  • configured root: gdrive by default
  • :path "<folder-id>"
  • :filename "<name>.<ext>"

Resulting runtime path shape:

workspaces/<ws>/storage/<root>/<folder-id>/<name>.<ext>

Google Docs/Sheets are exported to:

Source typeExport type
Docstext/plain (.txt)
Sheetsxlsx
Other Google-apps typespdf

Per-file metadata docs (KV-backed-by-Firestore)

For each downloaded file the flow writes a KV doc:

ItemShape
Key formatgoogle-drive-sync:meta:<folder-id>:<file-id>
Value fields:folder-id, :file-id, :blob-filename, plus Drive fields like :name, :mimeType, :modifiedTime, :size, :driveId

How to verify a run

After a run completes:

CheckExpected signal
download-files stepsuccesses / failures counts match expectations.
meta-<file-id> KV writesEntries show {:success true, :key "...", :created? ...}.
Cursor write step (set-cursor)Updates google-drive-sync:cursor (or your custom cursor key).

Related

As of Mar 25, 2026