π Professional Git Repository Backup and Synchronization System
A powerful, self-hosted solution for automated Git repository backups across GitHub, GitLab, Gitee, and local storage.
# Pull and run with Docker
docker pull onicc/gitsync:latest
# Create required directories
mkdir -p data backups docker_ssh
# Run the container
docker run -d \
--name gitsync \
-p 8080:8080 \
-v $(pwd)/data:/app/database \
-v $(pwd)/backups:/backups \
-v $(pwd)/docker_ssh:/root/.ssh \
onicc/gitsync:latest
# Access at http://localhost:8080- π Mirror Backup: Complete repository synchronization including all branches, tags, and commits
- β° Scheduled Sync: Flexible Cron-based scheduling for automated backups
- π Multi-Platform: Support for GitHub, GitLab, Gitee, and local repositories
- π Multi-SSH Key Support: Separate SSH keys for different platforms and users
- π Real-time Dashboard: Monitor backup status and activity logs
- π Secure Authentication: SSH key and Personal Access Token management
- π³ Docker Ready: Easy deployment with Docker and Docker Compose
- π Detailed Logging: Track all sync operations with error diagnostics
- πΎ Data Persistence: All data (database, SSH keys, backups) persists across restarts
Real-time monitoring with system statistics and live activity stream.
Manage all your backup tasks with intuitive controls.
Secure SSH key and access token management.
Detailed error logs and troubleshooting information.
- Backend: Python 3.11 + FastAPI
- Frontend: Vanilla JavaScript + Modern CSS
- Database: SQLite (single-node)
- Scheduler: APScheduler with Cron support
- Git Engine: GitPython + subprocess for mirror operations
The easiest way to deploy GitSync is using the pre-built image from Docker Hub.
docker pull onicc/gitsync:latestmkdir -p data backups docker_sshCreate a docker-compose.yml file:
name: gitsync
services:
gitsync:
image: onicc/gitsync:latest
container_name: gitsync
ports:
- "8080:8080"
volumes:
- ./data:/app/database
- ./backups:/backups
- ./docker_ssh:/root/.ssh
environment:
- DATABASE_URL=sqlite:////app/database/git_backup.db
- ENCRYPT_KEY=${ENCRYPT_KEY:-your_secret_key_here}
restart: unless-stoppeddocker-compose up -dOpen your browser and navigate to: http://localhost:8080
If you want to build the Docker image from source:
git clone https://github.com/Onicc/gitsync.git
cd gitsyncmkdir -p data backups docker_sshdocker-compose up -dThe application will:
- Build the Docker image
- Start the container
- Automatically configure SSH known_hosts
- Initialize the database
- Start the web server on port 8080
Open your browser and navigate to: http://localhost:8080
gitsync/
βββ data/ # Database files (persisted)
βββ backups/ # Backup repositories (persisted)
βββ docker_ssh/ # SSH keys and config (persisted)
βββ docker-compose.yml
βββ Dockerfile
# View logs
docker-compose logs -f
# Stop the application
docker-compose down
# Restart the application
docker-compose restart
# Rebuild and restart
docker-compose up -d --build
# View container status
docker ps | grep gitsyncLocal deployment gives you more control and easier debugging.
git clone https://github.com/Onicc/gitsync.git
cd gitsyncpython3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatecd backend
pip install -r requirements.txtThe database will be automatically created on first run.
# From the backend directory
uvicorn main:app --host 0.0.0.0 --port 8080 --reloadOr use Python directly:
python -m uvicorn main:app --host 0.0.0.0 --port 8080 --reloadOpen your browser and navigate to: http://localhost:8080
gitsync/
βββ backend/
β βββ main.py
β βββ database.py
β βββ models.py
β βββ git_engine.py
β βββ scheduler.py
β βββ api_*.py
β βββ requirements.txt
βββ frontend/
β βββ index.html
β βββ app.js
β βββ styles.css
βββ database/ # Database files
βββ temp_repos/ # Temporary clone directory
βββ venv/ # Virtual environment
SSH keys are required for authenticating with Git platforms using SSH URLs.
- Navigate to Credentials page
- Click Add SSH Key button
- Fill in the form:
- Platform: Select the Git platform (GitHub, GitLab, Gitee)
- User ID: Enter your username on that platform
- Key Name: Give it a descriptive name (optional)
- Click Generate Key
- The public key will be displayed and automatically copied to clipboard
- Add the public key to your Git platform:
- GitHub: Settings β SSH and GPG keys β New SSH key
- GitLab: Preferences β SSH Keys β Add new key
- Gitee: Settings β SSH Keys β Add SSH key
- Each platform + user combination gets its own SSH key
- Automatic SSH config management
- Keys are stored securely in
~/.ssh/(local) ordocker_ssh/(Docker) - SSH config automatically updated with Host aliases
Personal Access Tokens are required for HTTPS URLs.
- Navigate to Credentials page
- Click Add Token button
- Fill in the form:
- Platform: Select the Git platform
- User ID: Enter your username
- Token Name: Give it a descriptive name
- Token: Paste your Personal Access Token
- Scopes: Enter token permissions (e.g., repo, read:org)
- Click Add Token
- GitHub: Settings β Developer settings β Personal access tokens β Generate new token
- Required scopes:
repo(full control of private repositories)
- Required scopes:
- GitLab: Preferences β Access Tokens β Add new token
- Required scopes:
read_repository,write_repository
- Required scopes:
- Gitee: Settings β Private Token β Generate new token
- Required scopes:
projects,pull_requests
- Required scopes:
Click on Sync Tasks in the sidebar.
Click the Add Sync Task button.
- Name: Give your backup task a descriptive name
- Icon: Choose an emoji icon (optional)
- Platform: Select source platform
- Repository URL: Enter the source repository URL
- SSH format:
git@github.com:username/repo.git - HTTPS format:
https://github.com/username/repo.git
- SSH format:
- Authentication: Select SSH Key or Personal Access Token
- Platform: Select destination platform or Local
- Repository URL: Enter the destination URL or local path
- Remote:
git@github.com:username/backup-repo.git - Local:
/backups/my-backup(absolute path)
- Remote:
- Authentication: Select authentication method (for remote destinations)
- Cron Expression: Set backup schedule
- Every hour:
0 * * * * - Every day at 2 AM:
0 2 * * * - Every Monday at 3 AM:
0 3 * * 1 - Every 6 hours:
0 */6 * * *
- Every hour:
- Retry Count: Number of retry attempts on failure (default: 3)
Click Create Task to save. The task will be automatically enabled.
Click the Sync Now button on any backup task to trigger immediate synchronization.
Click the Edit button to modify task configuration.
Click the Delete button to remove a backup task.
Toggle the task status to enable or disable scheduled backups.
The Dashboard shows:
- Total backup tasks
- Active tasks
- Failed tasks
- Live activity stream with recent operations
The Diagnostics page provides:
- Detailed logs for all operations
- Failed task details with error messages
- Export logs functionality
- Clear all logs option
Edit docker-compose.yml to configure:
environment:
- DATABASE_URL=sqlite:////app/database/git_backup.db
- ENCRYPT_KEY=${ENCRYPT_KEY:-your_secret_key_here}DATABASE_URL: Database connection stringENCRYPT_KEY: Encryption key for storing credentials (change in production)
Create a .env file in the backend directory:
DATABASE_URL=sqlite:///./database/git_backup.db
ENCRYPT_KEY=your_secret_key_hereEdit docker-compose.yml:
ports:
- "8080:8080" # Change left side to use different host portChange the port in the uvicorn command:
uvicorn main:app --host 0.0.0.0 --port 8080The following directories are mapped to persist data:
volumes:
- ./data:/app/database # Database storage
- ./backups:/backups # Backup repositories
- ./docker_ssh:/root/.ssh # SSH keys and configProblem: "Host key verification failed"
Solution: The application automatically adds known_hosts on startup. If you still see this error:
# For Docker
docker-compose restart
# For Local
ssh-keyscan github.com >> ~/.ssh/known_hosts
ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
ssh-keyscan gitee.com >> ~/.ssh/known_hostsProblem: "Permission denied (publickey)"
Solution:
- Verify the SSH public key is added to your Git platform
- Check that the correct SSH key is selected for the task
- Ensure the User ID matches your Git platform username
Problem: "Invalid URL format"
Solution:
- SSH URLs must match:
git@host:username/repository.git - HTTPS URLs must match:
https://host/username/repository.git - Ensure authentication method matches URL format:
- SSH Key β SSH URL
- Personal Access Token β HTTPS URL
Problem: Log timestamps show wrong time
Solution: The application uses local system time. For Docker:
# Add to docker-compose.yml
environment:
- TZ=Asia/Shanghai # Change to your timezoneProblem: "Database is locked"
Solution:
# Stop the application
docker-compose down # or kill the local process
# Remove lock file
rm data/git_backup.db-journal
# Restart
docker-compose up -dProblem: Docker container in restart loop
Solution:
# Check logs
docker logs gitsync
# Common issues:
# 1. Port already in use - change port in docker-compose.yml
# 2. Permission issues - check directory permissions
# 3. Database corruption - backup and remove data/git_backup.db- Change Default Encryption Key: Update
ENCRYPT_KEYin production - Use SSH Keys: Prefer SSH authentication over tokens when possible
- Limit Token Scopes: Only grant necessary permissions to tokens
- Regular Backups: Backup the
data/directory regularly - Secure Access: Use reverse proxy with HTTPS in production
- Network Isolation: Run in isolated network or use firewall rules
- Backup Size: Large repositories (>1GB) may take longer to sync
- Schedule Wisely: Avoid scheduling all tasks at the same time
- Local Backups: Local destinations are faster than remote
- Retry Count: Set appropriate retry count based on network stability
- Cleanup: Regularly clean up old logs from Diagnostics page
# Install test dependencies
pip install pytest pytest-asyncio
# Run tests
pytestbackend/
βββ main.py # FastAPI application entry point
βββ database.py # Database initialization and session management
βββ models.py # SQLAlchemy models
βββ git_engine.py # Git operations and sync logic
βββ scheduler.py # APScheduler task scheduling
βββ api_tasks.py # Backup task API endpoints
βββ api_stats.py # Statistics and logs API endpoints
βββ api_credentials.py # Credentials management API endpoints
βββ crypto_utils.py # Encryption utilities
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
For issues and questions:
- GitHub Issues: https://github.com/Onicc/gitsync/issues
- Documentation: https://github.com/Onicc/gitsync/wiki
- FastAPI for the excellent web framework
- APScheduler for reliable task scheduling
- GitPython for Git operations
- All contributors and users of this project



