Skip to content

Instantly share code, notes, and snippets.

@mko
Forked from jazzychad/gist:3861848
Created October 9, 2012 22:33
Show Gist options
  • Save mko/3861881 to your computer and use it in GitHub Desktop.
Save mko/3861881 to your computer and use it in GitHub Desktop.
git post-receive hook to tar the repo and send to s3 for backup
#!/bin/bash
# a post-receive hook for git servers to tar the current repo and send to s3 for backup
# save as 'post-receive' and put it in .git/hooks of desired repo(s), chmod +x
# assumes you have the s3cmd program installed and configured (sudo apt-get install s3cmd)
echo "thanks for the push. have a nice day."
# configure your S3BUCKET name, the rest should be automatic
# you can optionally change the S3TGZ name format to your taste
S3BUCKET=your-s3-bucket-name-goes-here
PWD=`pwd`
BASE=`basename $PWD`
TGZ=/tmp/$BASE.tgz
S3PATH=s3://$S3BUCKET/$BASE
# stick a unix timestamp in the final tgz filename
S3TGZ=$S3PATH/`date +%s`-$BASE.tgz
echo "PWD is $PWD"
echo "BASE is $BASE"
echo "TGZ is $TGZ"
echo "tar command: tar czvf $TGZ $BASE"
echo "tgz'ing..."
cd ..
# force rm old archive
rm -f $TGZ
# tar files
tar czvf $TGZ $BASE
# upload to s3
# nuke old backups (optional)
#s3cmd del $S3PATH/ --recursive
# put new backup
s3cmd put $TGZ $S3TGZ
echo "done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment