A lightweight, cross‑platform Python utility that turns any local folder into your personal Google Drive “Dropbox” clone—perfect for automated backups, versioning, and seamless cloud storage.
- OAuth2 Authentication
Securely authenticate via Google’s OAuth2 flow; tokens are stored intoken.jsonand automatically refreshed. - Idempotent Folder Management
Looks up (or creates) a Drive folder namedBackupFoler2022and reuses it on every run—no duplicate folders. - Chunked File Uploads
Streams large files in chunks withMediaFileUploadfor reliable, resumable transfers. - Cross‑Platform Support
Pure Python (3.6+) solution with no OS‑specific binaries—runs on Windows, macOS, and Linux. - Scheduler‑Ready
Integrates seamlessly withcron(Linux/macOS) or Task Scheduler (Windows) for hands‑off periodic syncs. - Error Handling
Graceful handling of network interruptions and API errors, with clear console logging.
- Clone the repo
git clone https://github.com/dth99/gdrive.git cd gdrive
2. **Create & activate a virtual environment**
```bash
python3 -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows
-
Install dependencies
pip install -r requirements.txt
-
Set up Google API credentials
- Go to the Google Cloud Console.
- Create/select a project and enable the Google Drive API.
- Create OAuth2 credentials (Desktop app), download
credentials.json, and place it in the project root.
-
SCOPES By default the script uses:
SCOPES = ["https://www.googleapis.com/auth/drive"]
to grant full Drive access.
-
Local folder to back up Edit the
backupfiles/path inbackup.pyif you wish to sync a different directory.
Run the script to perform the initial OAuth flow and upload:
python backup.pyTypical console output:
Token not found—launching browser for authentication...
Authenticated! Token saved to token.json.
Backup folder found/created with ID: 1AbcD2EfGh...
Backing up file: project1.py
Backing up file: notes.txt
…
-
Open your crontab:
crontab -e
-
Add a line to run hourly:
0 * * * * /path/to/venv/bin/python /path/to/gdrive/backup.py >> /path/to/gdrive/logs/backup.log 2>&1
-
Open Task Scheduler → Create Basic Task.
-
Set a trigger (e.g., daily/hourly).
-
Action: Start a program
- Program/script:
C:\path\to\venv\Scripts\python.exe - Add arguments:
"C:\path\to\gdrive\backup.py"
- Program/script:
google-authgoogle-auth-oauthlibgoogle-api-python-client
Install with:
pip install google-auth google-auth-oauthlib google-api-python-clientContributions are welcome! Please:
- Fork the repo
- Create a branch (
git checkout -b feature/YourFeature) - Commit changes (
git commit -m "Add YourFeature") - Push (
git push origin feature/YourFeature) - Open a Pull Request
This project is licensed under the MIT License—see the LICENSE file for details.
- LinkedIn: deepakkumar2o
- Email: deep99.official@gmail.com
Feel free to connect or send any questions!





