Skip to content

Instantly share code, notes, and snippets.

@cato-
Created November 16, 2014 17:18
Show Gist options
  • Save cato-/f0d2cda0070911da1887 to your computer and use it in GitHub Desktop.
Save cato-/f0d2cda0070911da1887 to your computer and use it in GitHub Desktop.
Backup all public repositories of specified user, designed to run from daily cron
#!/bin/bash
USER=$1
if [ -n "$2" ]; then
VERBOSE=echo
else
VERBOSE=:
fi
umask 0027
cd $(dirname $0)
curl -s https://api.github.com/users/${USER}/repos?type=owner | grep git_url | sed 's,^.* ",,; s/",$//;' | while read l; do
if [ ! -e $(basename $l) ]; then
$VERBOSE "Initial Backup of $l"
git clone --quiet --mirror $l;
echo "section=GitHub Backup" > $(basename $l)/cgitrc
echo "Backup of $l" > $(basename $l)/description
fi;
done
for d in *.git; do
$VERBOSE "Update of $d"
git --git-dir $d remote update > /dev/null;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment