Skip to content

Instantly share code, notes, and snippets.

@allebb
Forked from philippb/git-backup-to-AWS-S3.sh
Created August 29, 2017 18:44
Show Gist options
  • Save allebb/1b2bcb0ef426bdea36cbf0281651fee4 to your computer and use it in GitHub Desktop.
Save allebb/1b2bcb0ef426bdea36cbf0281651fee4 to your computer and use it in GitHub Desktop.

Revisions

  1. @philippb philippb renamed this gist Mar 6, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @philippb philippb renamed this gist Mar 6, 2012. 1 changed file with 12 additions and 9 deletions.
    21 changes: 12 additions & 9 deletions gistfile1.sh → git-backup-to-AWS-S3
    Original file line number Diff line number Diff line change
    @@ -11,14 +11,14 @@ account=$GITHUB_ACCOUNT
    # Setup repository to $1
    repository=$1

    date=`date '+%m%d%y%H%M%S'`
    date=`date '+%Y%m%d%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
    git clone --mirror [email protected]:$account/$repository.git $dir/$repository.$date.git
    if [ $? -ne 0 ]; then
    echo "Error cloning $repository"
    exit 1
    @@ -30,22 +30,25 @@ if [ $? -ne 0 ]; then
    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
    #Optional file encryption
    #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
    if [ -f $dir/$repository.$date.git.tar.gz ]; then
    s3cmd put $dir/$repository.$date.git.tar.gz s3://$bucket/git.$repository.$date.git.tar.gz
    fi

    if [ $? -ne 0 ]; then
    echo "Error uploading $repository to S3"
    exit 1
    fi

    #delete tar file and checked out folder
    /bin/rm $dir/$repository.$date.git.tar.gz
    /bin/rm -rf $dir/$repository.$date.git
    if [ $? -ne 0 ]; then
    echo "Error removing $repository"
    exit 1
  3. @weavenet weavenet revised this gist Dec 27, 2011. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,8 @@
    # cat backup_git_repo.sh
    #!/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
    date=`date '+%m%d%y%H%M%S'`
    bucket=$GITHUB_BACKUP_BUCKET
    dir=$GITHUB_BACKUP_DIR
    password=$GITHUB_BACKUP_PASSWORD
    @@ -13,6 +11,9 @@ 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"
  4. @weavenet weavenet revised this gist Dec 27, 2011. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,9 @@
    # cat backup_git_repo.sh
    #!/bin/bash

    # script to backup git repo to S3
    # set bucket, backup, password and acocunt in your localrc file
    # 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
    date=`date '+%m%d%y%H%M%S'`
    bucket=$GITHUB_BACKUP_BUCKET
    dir=$GITHUB_BACKUP_DIR
  5. @weavenet weavenet revised this gist Dec 27, 2011. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,9 @@
    # script to backup git repo to S3
    # set bucket, backup, password and acocunt in your localrc file
    date=`date '+%m%d%y%H%M%S'`
    bucket=$BACKUP_BUCKET
    dir=$BACKUP_DIR
    password=$BACKUP_PASSWORD
    bucket=$GITHUB_BACKUP_BUCKET
    dir=$GITHUB_BACKUP_DIR
    password=$GITHUB_BACKUP_PASSWORD
    account=$GITHUB_ACCOUNT

    # Setup repository to $1
  6. @weavenet weavenet created this gist Dec 27, 2011.
    52 changes: 52 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    # cat backup_git_repo.sh
    #!/bin/bash

    # script to backup git repo to S3
    # set bucket, backup, password and acocunt in your localrc file
    date=`date '+%m%d%y%H%M%S'`
    bucket=$BACKUP_BUCKET
    dir=$BACKUP_DIR
    password=$BACKUP_PASSWORD
    account=$GITHUB_ACCOUNT

    # Setup repository to $1
    repository=$1

    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"