Skip to content

Instantly share code, notes, and snippets.

@thuss
Created December 8, 2010 17:49
Show Gist options
  • Save thuss/733623 to your computer and use it in GitHub Desktop.
Save thuss/733623 to your computer and use it in GitHub Desktop.
A simple script to backup github repositories
#!/bin/bash -e
#
# This script clones or fetches the latest updates from selected repo's and then tar's them up
#
CHECKOUT_DIR=$HOME/backups/checkouts
BACKUP_DIR=$HOME/backups/tarballs
LOG=/tmp/github-daily-backups.log
REPOS="vm-main vm-cdn vm-operations-chef vm-iphone vm-contrib"
function clone_or_fetch {
cd $CHECKOUT_DIR
if [ -d $1 ]; then
echo "Fetching $1" >> $LOG
cd $1
git fetch origin >> $LOG
else
echo "Cloning $1" >> $LOG
git clone -n [email protected]:volunteermatch/${1}.git >> $LOG
fi
}
# Fetch (update) or clone (checkout) each repo
echo `date` : starting $0 >> $LOG
for repo in $REPOS
do
clone_or_fetch $repo
done
# Create the daily tarball using the day of the month in the filename
cd $CHECKOUT_DIR
echo Tarring and bzipping backup to $BACKUP_DIR/nightly-for-day-`date +%d`.tbz >> $LOG
tar -cjf $BACKUP_DIR/nightly-for-day-`date +%d`.tbz $REPOS >> $LOG
echo `date` : finished $0 >> $LOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment