Skip to content

Instantly share code, notes, and snippets.

@bdha
Last active August 29, 2015 14:19
Show Gist options
  • Save bdha/65ce9d76b39ba72c181f to your computer and use it in GitHub Desktop.
Save bdha/65ce9d76b39ba72c181f to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
#set -x
TOKEN=$( cat /root/.github-token )
BASEURL="https://api.github.com/orgs/${1}/repos?type=owner&access_token=${TOKEN}&per_page=100"
BACKUPS_ZFS="zones/$( zonename )/data/backup/github"
BACKUPS_ROOT="/var/helium/backups/github"
function get_repo {
REPO=$1
DIR=$(echo "${REPO}" | sed -e 's#.*/##' )
if [ ! -f "$BACKUPS_ROOT/$DIR/config" ]; then
echo "Cloning $REPO ($DIR)"
zfs create -p $BACKUPS_ZFS/$DIR
cd $BACKUPS_ROOT
git clone --mirror $REPO
else
echo "Updating $REPO ($DIR)"
cd $BACKUPS_ROOT/$DIR
git fetch -p origin
cd $BACKUPS_ROOT
fi
}
zfs create -p $BACKUPS_ZFS
MOUNT=$( zfs get -H -o value mountpoint $BACKUPS_ZFS )
# zfs set mountpoint trying to umount, which fails for good reasons. Check the
# mountpoint before setting it.
if [ "$MOUNT" != "$BACKUPS_ROOT" ] ; then
zfs set mountpoint=$BACKUPS_ROOT $BACKUPS_ZFS
fi
for REPO in $( curl -s "${BASEURL}" | json -a ssh_url ) ; do
get_repo $REPO
WIKI_REPO=$( echo $REPO | sed -e 's/\.git/.wiki.git/' )
# This might fail if has_wiki=false, or there are no wiki pages yet.
set +e
get_repo $WIKI_REPO
set -e
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment