This repository contains a Python script to backup all your GitHub repositories to a local directory. The script uses the GitHub API to fetch the list of repositories and clones or pulls them to keep the backup up-to-date.
-
Clone this repository to your local machine:
git clone https://github.com/gabrielfortuny/backup-github-repos.git cd backup-github-repos
-
Create a virtual environment and activate it:
python3 -m venv env source env/bin/activate
-
Install the required packages:
pip install -r requirements.txt
-
Create a
.env
file in the root directory of the project and add your GitHub token and backup directory path:GITHUB_TOKEN=your_github_token BACKUP_DIR=/path/to/backup/directory
GITHUB_TOKEN
: A personal access token with read access to your repositories. You can create one here.BACKUP_DIR
: The directory where you want to store the backups.
Run the script to start the backup process:
python3 backup_github_repos.py
The script will fetch all your repositories and clone them to the specified backup directory. If a repository already exists, it will pull the latest changes.
- Ensure that your GitHub token has the necessary permissions to access your repositories.
- The script handles pagination to fetch all repositories if you have more than 100.
This project is licensed under the MIT License. See the LICENSE file for details.