I have a reasonably large github account. I now have over 200 repos across private and public, and one of the items I’ve been meaning to do is to back up these repos more efficiently.
I already keep local copies of those I am actively tinkering with and can pull them down at a moment’s notice, but a more robust set-and-forget backup method was needed. After all, I should keep a copy of my repos just in case of a disaster.
So I looked into SAAS options, and given that most of my repos are open source or just plugins I have modified for various reasons, i.e faster activations, allowing activation from wp-config, etc. I wanted a simple, free method.
This is complicated because I am a Windows user, and we all know this makes this sort of thing harder. Most people expect development on a Mac, so I decided I would use the Git CLI. I already had it installed, but it’s really easy to do if you have Winget installed
winget install --id GitHub.cli
I am already authenticated as I use get on the command line and via Sublime Merge often, but then the next thing to do would be to authorise login using the following command.
gh auth login
Just follow the instructions for a browser authentication or an SSH authentication.
So, on my backup partition,, I set up a GitHub backup folder and wrote a batch script to allow me to automatically backup via clone all my repo’s
@echo off
setlocal enabledelayedexpansion
set BACKUP_DIR=D:\GitHub Backup
mkdir "%BACKUP_DIR%" 2>nul
cd /d "%BACKUP_DIR%"
for /f "tokens=1,2 delims=/" %%a in ('gh repo list --limit 1000 --json nameWithOwner --jq ".[]|.nameWithOwner"') do (
set "REPO_NAME=%%b"
if exist "!REPO_NAME!" (
echo Updating repository: !REPO_NAME!
cd "!REPO_NAME!" && git pull && cd ..
) else (
echo Cloning repository: !REPO_NAME!
git clone "https://github.com/%%a/%%b.git" "!REPO_NAME!"
)
)
echo Backup complete.
pause
BAT (Batchfile)Let it run overnight and about four gigabytes later my backup is done, I now need to run it once a day and it will pull me the latest update and its even better because syncbackpro now automatically backs this up to my archive drive too so I have two local copies one on NVME one on Hard Drive and one on GitHub.
This now runs automatically and is synced automatically too, another job checked off the list.