This repository contains a Python script that backs up a specified Git repository to a designated folder on Google Drive. The script uses the Google Drive API to authenticate, create folders, and upload files, ensuring that the backup process is seamless and automated.
Automated backup of Git repositories to Google Drive.
Support for specific commit hashes or tags for backup.
Creation of a structured folder hierarchy on Google Drive, mirroring the repository's directory structure.
Authentication with Google Drive using OAuth 2.0.
Generation of a changelog file for the backup, detailing the commits included.
Python 3.6 or later.
Google Drive API credentials (JSON file).
`gitpython` library for Git operations.
`google-auth`, `google-auth-oauthlib`, and `google-api-python-client` libraries for Google Drive API interactions.
First, clone the repository to your local machine:
git clone https://github.com/Frost752/clonegittodrive.git
cd clonegittodriveCreate a virtual environment in your project folder:
python3 -m venv venvOn macOS/Linux:
source venv/bin/activateOn Windows:
.\venv\Scripts\activateWith the virtual environment active, install the dependencies listed in src/requirements.txt:
pip install -r src/requirements.txtBefore you can interact with Google Drive through the API, you need to set up the credentials and configure the necessary permissions. Follow these steps:
-
Go to the Google Cloud Console:
- Open the Google Cloud Console.
-
Create a New Project:
- In the Cloud Console, click on the project dropdown on the top-left, then click New Project.
- Enter a name for your project and select your billing account (if applicable).
- Click Create.
-
Navigate to the API Library:
- In the Google Cloud Console, open the Navigation menu (top-left) > APIs & Services > Library.
-
Enable Google Drive API:
- In the search bar, type
Google Drive API. - Click on it and then click Enable.
- In the search bar, type
-
Go to the Credentials Page:
- In the Google Cloud Console, open APIs & Services > Credentials.
-
Create Credentials:
- Click on the Create Credentials button and select OAuth client ID.
-
Configure OAuth Consent Screen:
- If you haven’t configured the consent screen yet, you'll need to do so. Fill in the required fields (app name, user support email, etc.).
- Under Scopes, you can leave the default settings unless you need to request specific permissions.
- Click Save and Continue.
-
Choose Application Type:
- Select Desktop App as the application type.
- Provide a name for your OAuth 2.0 client (e.g., "Drive API Client").
- Click Create.
-
Download
credentials.json:- After creating the credentials, you’ll see a dialog with your newly created credentials.
- Click the Download button to download the
credentials.jsonfile. This file contains the client ID and secret needed to authenticate your app.
Use the command line to run the backup script with the appropriate arguments.
python src/main.py --repo /path/to/repo --folder YOUR_DRIVE_FOLDER_ID [--commit COMMIT_HASH_OR_TAG]--repo or -r: Path to the Git repository (default: current directory).
--folder or -f: Google Drive root folder ID for backups (required).
--commit or -c: Specific commit hash or tag to back up (default: HEAD).
Clone the repo with:
git clone https://github.com/Frost752/clonegittodrive.git
cd clonegittodriveContributions are welcome! Please open an issue or submit a pull request if you have any improvements or new features to add.