Created
December 27, 2011 15:50
-
-
Save weavenet/1524092 to your computer and use it in GitHub Desktop.
Quick github repo backup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to backup git repo to S3 | |
# Set bucket, dir, password and account to use for the backup. I keep mine in local env vars | |
# These are set by localrc which lives on an encrypted home directory and is executed by my bashrc | |
bucket=$GITHUB_BACKUP_BUCKET | |
dir=$GITHUB_BACKUP_DIR | |
password=$GITHUB_BACKUP_PASSWORD | |
account=$GITHUB_ACCOUNT | |
# Setup repository to $1 | |
repository=$1 | |
date=`date '+%m%d%y%H%M%S'` | |
# Create the backup directory | |
mkdir -p $dir | |
echo "Backing up $repository" | |
git clone [email protected]:$account/$repository.git $dir/$repository.$date.git | |
if [ $? -ne 0 ]; then | |
echo "Error cloning $repository" | |
exit 1 | |
fi | |
tar cpzf $dir/$repository.$date.git.tar.gz $dir/$repository.$date.git | |
if [ $? -ne 0 ]; then | |
echo "Error compressing $repository" | |
exit 1 | |
fi | |
echo $password | gpg -c --passphrase-fd 0 $dir/$repository.$date.git.tar.gz | |
if [ $? -ne 0 ]; then | |
echo "Error encrypting $repository" | |
exit 1 | |
fi | |
if [ -f $dir/$repository.$date.git.tar.gz.gpg ]; then | |
s3cmd put $dir/$repository.$date.git.tar.gz.gpg s3://$bucket/git.$repository.$date.git.tar.gz.gpg | |
fi | |
if [ $? -ne 0 ]; then | |
echo "Error uploading $repository to S3" | |
exit 1 | |
fi | |
/bin/rm $dir/$repository.$date.git.tar.gz | |
if [ $? -ne 0 ]; then | |
echo "Error removing $repository" | |
exit 1 | |
fi | |
echo "Succesfully backed up $repository" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment