A Python-based utility to backup specific folders from Google Drive to Google Cloud Storage (GCS). This solution is Dockerized and designed to be deployed via Google Cloud Build/Cloud Run or scheduled via Cloud Scheduler.
- Automated Backup: Recursively copies files from a source Google Drive folder.
- Cloud Storage Integration: Uploads files directly to a specified GCS Bucket.
- Docker Ready: Includes a
Dockerfilefor easy containerization. - CI/CD Integrated: Includes
cloudbuild.yamlfor Google Cloud Build pipelines. - Jupyter Support: Includes notebooks for data exploration or testing.
Before running this script, you need:
- Google Cloud Project: A valid GCP project.
- Service Account:
- Create a Service Account in IAM.
- Download the JSON Key file.
- Grant the Service Account the Storage Object Admin role.
- Google Drive API: Enable the Drive API in your GCP project.
- Drive Permissions: Share the target Google Drive folder with the Service Account email address (e.g.,
my-app@project-id.iam.gserviceaccount.com).
The application relies on environment variables. You can set these in a .env file for local development or in your Cloud Run/Build configuration.
| Variable | Description | Example |
|---|---|---|
PROJECT_ID |
Your Google Cloud Project ID | my-backup-project |
SOURCE_FOLDER_ID |
The ID of the Google Drive folder to backup | 1A2B3C... |
BUCKET_NAME |
The name of the GCS bucket | my-drive-backups |
-
Clone the repository
git clone [https://github.com/XaverHeuser/GDrive-Backup.git](https://github.com/XaverHeuser/GDrive-Backup.git) cd GDrive-Backup -
Install Dependencies
pip install -r requirements.txt
-
Setup Google Cloud environments
-
Run the Script
python main.py
This project includes a cloudbuild.yaml. To trigger a build:
gcloud builds submit --config cloudbuild.yaml .To set up an automated schedule:
-
Deploy the image to Cloud Run.
-
Create a Cloud Scheduler job to trigger the Cloud Run service endpoint (e.g., every night at 3 AM).
Load data from Google Cloud Storage to local PC:
- Open Google Cloud SDK Shell
- Navigate to the target folder
- Enter the following command:
date = YYYY-MM-DD_HH-mm
gsutil -m cp -r "gs://gdrive-backup-2026/backup_{date}" .
- src/: Source code modules.
- notebooks/: Jupyter notebooks for testing API connections or data analysis.
- main.py: Entry point for the backup script.
- Dockerfile: Container definition.
This project is licensed under the MIT License - see the LICENSE file for details.