Skip to content

open-navigation/opennav_epic_shelter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Repository Mirror Backup System

This system automatically mirrors GitHub repositories to your local machine, preserving all branches, tags, and refs. The mirrors are kept in sync with daily automatic updates via cron.

Features

  • Mirror multiple GitHub repositories with a single command
  • Preserves all branches and tags (no pruning)
  • Automatic daily updates at midnight via cron
  • Detailed logging of all backup operations
  • Automatic log rotation (keeps last 30 days)
  • Color-coded console output for easy monitoring
  • Handles both initial cloning and incremental updates

Directory Structure

opennav_repo_backups/
├── BACKUP_REPOS.TXT      # List of repositories to mirror
├── mirror_repos.sh        # Main backup script
├── setup_cron.sh          # Cron setup script
├── README.md              # This file
├── mirrors/               # Mirrored repositories (created automatically)
│   ├── ros-navigation_navigation2.git/
│   └── ros-navigation_docs.nav2.org.git/
└── logs/                  # Backup logs (created automatically)
    └── mirror_YYYYMMDD_HHMMSS.log

Initial Setup

1. Configure Repositories to Backup

Edit BACKUP_REPOS.TXT and add the repositories you want to mirror (one per line):

ros-navigation/navigation2
ros-navigation/docs.nav2.org

Format: owner/repository

You can add comments by starting a line with #:

# ROS Navigation repositories
ros-navigation/navigation2
ros-navigation/docs.nav2.org

# Additional repos
another-org/another-repo

2. Set Up Automatic Daily Backups

Run the cron setup script:

./setup_cron.sh

This will configure a cron job to run the backup script daily at midnight (00:00).

3. Run Your First Backup (Optional)

You can run an immediate backup without waiting for the cron schedule:

./mirror_repos.sh

Usage

Manual Backup

To run a backup manually at any time:

./mirror_repos.sh

Adding New Repositories

  1. Edit BACKUP_REPOS.TXT
  2. Add new repository in the format owner/repository
  3. Save the file

The new repository will be included in the next scheduled backup, or you can run ./mirror_repos.sh immediately.

Viewing Logs

Logs are stored in the logs/ directory with timestamps. To view the most recent log:

ls -t logs/ | head -1 | xargs -I {} cat logs/{}

Or view all recent logs:

ls -lht logs/

Checking Cron Status

To verify the cron job is installed:

crontab -l | grep mirror_repos.sh

To view cron execution logs:

# Ubuntu/Debian
grep CRON /var/log/syslog | grep mirror_repos

# Systems with systemd
journalctl -u cron | grep mirror_repos

Removing the Cron Job

To stop automatic backups:

crontab -e

Then delete the line containing mirror_repos.sh, save and exit.

How It Works

Mirroring Process

  1. The script reads all repositories from BACKUP_REPOS.TXT
  2. For each repository:
    • First time: Clones the repository as a mirror using git clone --mirror
    • Subsequent runs: Updates the existing mirror using git remote update
  3. No pruning: All branches and refs are preserved, even if deleted from the remote
  4. Each operation is logged with timestamps

Mirror vs Regular Clone

A mirror clone (git clone --mirror) creates a bare repository that includes:

  • All branches
  • All tags
  • All refs
  • All remote tracking information

This is ideal for backups as it captures the complete repository state.

Storage Location

Mirrors are stored in the mirrors/ directory with the naming format:

owner_repository.git

For example:

  • ros-navigation/navigation2mirrors/ros-navigation_navigation2.git/

Working with Mirrored Repositories

Clone from a Mirror

To create a working copy from a mirror:

git clone mirrors/ros-navigation_navigation2.git/ working-copy

View Mirror Contents

To see all branches in a mirror:

cd mirrors/ros-navigation_navigation2.git/
git branch -a

To see all tags:

cd mirrors/ros-navigation_navigation2.git/
git tag -l

Push Mirror to Another Remote

If you need to push a mirror to another GitHub account or Git server:

cd mirrors/ros-navigation_navigation2.git/
git push --mirror https://github.com/your-account/new-repo.git

Troubleshooting

Permission Denied

If you get permission denied errors, make scripts executable:

chmod +x mirror_repos.sh setup_cron.sh

Cron Job Not Running

  1. Check cron is installed and running:

    systemctl status cron
  2. Verify the cron job exists:

    crontab -l
  3. Check system logs for cron errors:

    grep CRON /var/log/syslog

Failed Repository Updates

Check the latest log file in logs/ for error messages. Common issues:

  • Network connectivity problems
  • Repository no longer exists or is private
  • Insufficient disk space

Disk Space

Monitor disk usage as mirrors can grow large:

du -sh mirrors/

Advanced Configuration

Change Cron Schedule

Edit the cron job to run at a different time:

crontab -e

Modify the schedule (format: minute hour day month weekday):

  • 0 0 * * * - Midnight daily (default)
  • 0 2 * * * - 2:00 AM daily
  • 0 0 * * 0 - Midnight every Sunday
  • 0 */6 * * * - Every 6 hours

Custom Backup Location

Edit mirror_repos.sh and change the BACKUP_DIR variable:

BACKUP_DIR="/path/to/custom/backup/location"

Maintenance

Log Cleanup

Logs older than 30 days are automatically deleted. To change this, edit the cleanup line in mirror_repos.sh:

find "$LOG_DIR" -name "mirror_*.log" -type f -mtime +30 -delete

Change +30 to your desired number of days.

Verify Mirror Integrity

To verify a mirror is healthy:

cd mirrors/ros-navigation_navigation2.git/
git fsck --full

Backup Best Practices

  1. Regularly verify backups are running (check logs weekly)
  2. Test restoration occasionally by cloning from mirrors
  3. Monitor disk space usage
  4. Keep the backup directory on a separate disk/partition for better reliability
  5. Consider additional offsite backups for critical repositories

License

These scripts are provided as-is for backup purposes.

Support

For issues or questions:

  • Check the logs in logs/ directory
  • Review the troubleshooting section above
  • Ensure scripts have execute permissions
  • Verify cron is running correctly

About

Scripts for backing up key repos in case of catastrophic disaster

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages