Skip to content

Instantly share code, notes, and snippets.

@johanneslamers
Forked from jstnkrr/awsbackup.sh
Created February 27, 2017 15:01
Show Gist options
  • Save johanneslamers/62c8d4ff9eb76e368fe41d63032fb7c7 to your computer and use it in GitHub Desktop.
Save johanneslamers/62c8d4ff9eb76e368fe41d63032fb7c7 to your computer and use it in GitHub Desktop.

Revisions

  1. @jstnkrr jstnkrr revised this gist Oct 13, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions awsbackup.sh
    Original file line number Diff line number Diff line change
    @@ -28,6 +28,7 @@ fi
    rm -fr $tmp_dir/*

    db_destination=db/`hostname`/
    echo $db_destination
    s3cmd sync --recursive --preserve /var/lib/automysqlbackup/ s3://$BUCKET/$db_destination

    shopt -s dotglob
  2. @jstnkrr jstnkrr revised this gist Oct 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion awsbackup.sh
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ fi

    rm -fr $tmp_dir/*

    db_destination = db/`hostname`/
    db_destination=db/`hostname`/
    s3cmd sync --recursive --preserve /var/lib/automysqlbackup/ s3://$BUCKET/$db_destination

    shopt -s dotglob
  3. @jstnkrr jstnkrr revised this gist Oct 13, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion awsbackup.sh
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,8 @@ fi

    rm -fr $tmp_dir/*

    s3cmd sync --recursive --preserve /var/lib/automysqlbackup/ s3://$BUCKET/db/`hostname`/
    db_destination = db/`hostname`/
    s3cmd sync --recursive --preserve /var/lib/automysqlbackup/ s3://$BUCKET/$db_destination

    shopt -s dotglob

  4. @jstnkrr jstnkrr revised this gist Oct 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion awsbackup.sh
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ fi

    rm -fr $tmp_dir/*

    s3cmd sync --recursive --preserve /var/lib/automysqlbackup/ s3://$BUCKET/db/
    s3cmd sync --recursive --preserve /var/lib/automysqlbackup/ s3://$BUCKET/db/`hostname`/

    shopt -s dotglob

  5. @jstnkrr jstnkrr revised this gist Oct 13, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions awsbackup.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/bash

    export BUCKET=filament-sp-backup/`hostname`
    export BUCKET=filament-sp-backup

    date_daily=`date +"%Y-%m-%d"`
    tmp_dir=/tmp/sp-backup-$date_daily
    @@ -11,16 +11,16 @@ week_day=`date +"%u"`

    # On first month day do
    if [ "$month_day" -eq 1 ] ; then
    destination=$tmp_dir/monthly/$date_daily
    destination=$tmp_dir/monthly/`hostname`/$date_daily
    type="monthly"
    else
    # On saturdays do
    if [ "$week_day" -eq 6 ] ; then
    destination=$tmp_dir/weekly/$date_daily
    destination=$tmp_dir/weekly/`hostname`/$date_daily
    type="weekly"
    else
    # On any regular day do
    destination=$tmp_dir/daily/$date_daily
    destination=$tmp_dir/daily/`hostname`/$date_daily
    type="daily"
    fi
    fi
  6. @jstnkrr jstnkrr revised this gist Sep 26, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion awsbackup.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #/bin/bash
    #!/bin/bash

    export BUCKET=filament-sp-backup/`hostname`

  7. @jstnkrr jstnkrr revised this gist Sep 25, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions awsbackup.sh
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ find /srv/users/* -prune -type d | while read d; do
    app=$(basename "$e")

    # skip daily dev site backups
    if ([[ "$app" =~ ^(dev|staging) ]] || [[ "$app" =~ (dev|staging)$ ]]) && [[ "$type" == "daily" ]] ; then
    if ([[ "$app" =~ ^(dev|staging|proto) ]] || [[ "$app" =~ (dev|staging|proto)$ ]]) && [[ "$type" == "daily" ]] ; then
    continue
    fi

    @@ -55,9 +55,9 @@ find /srv/users/* -prune -type d | while read d; do
    done
    done

    find /etc/apache-sp/vhosts.d/*.d/*.conf ! -name "main.conf" -exec tar -rvf $tmp_dir/sp-config.tar {} \;
    find /etc/nginx-sp/vhosts.d/*.d/*.conf ! -name "main.conf" -exec tar -rvf $tmp_dir/sp-config.tar {} \;
    find /etc/nginx-sp/ssl/ -type f -exec tar -rvf $tmp_dir/sp-config.tar {} \;
    find /etc/apache-sp/vhosts.d/*.d/*.conf ! -name "main.conf" -exec tar -rvf $destination/sp-config.tar {} \;
    find /etc/nginx-sp/vhosts.d/*.d/*.conf ! -name "main.conf" -exec tar -rvf $destination/sp-config.tar {} \;
    find /etc/nginx-sp/ssl/ -type f -exec tar -rvf $destination/sp-config.tar {} \;


    s3cmd put --recursive $tmp_dir/* s3://$BUCKET/
  8. @jstnkrr jstnkrr revised this gist Sep 25, 2015. 1 changed file with 26 additions and 11 deletions.
    37 changes: 26 additions & 11 deletions awsbackup.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #/bin/bash

    export BUCKET=filament-sp-backup/counsel-toronto
    export BUCKET=filament-sp-backup/`hostname`

    date_daily=`date +"%Y-%m-%d"`
    tmp_dir=/tmp/sp-backup-$date_daily
    @@ -11,29 +11,40 @@ week_day=`date +"%u"`

    # On first month day do
    if [ "$month_day" -eq 1 ] ; then
    destination=$tmp_dir/monthly/$date_daily
    destination=$tmp_dir/monthly/$date_daily
    type="monthly"
    else
    # On saturdays do
    if [ "$week_day" -eq 6 ] ; then
    destination=$tmp_dir/weekly/$date_daily
    else
    # On any regular day do
    destination=$tmp_dir/daily/$date_daily
    fi
    # On saturdays do
    if [ "$week_day" -eq 6 ] ; then
    destination=$tmp_dir/weekly/$date_daily
    type="weekly"
    else
    # On any regular day do
    destination=$tmp_dir/daily/$date_daily
    type="daily"
    fi
    fi

    rm -fr $destination/*
    rm -fr $tmp_dir/*

    s3cmd sync --recursive --preserve /var/lib/automysqlbackup/ s3://$BUCKET/db/

    shopt -s dotglob


    find /srv/users/* -prune -type d | while read d; do

    user=$(basename "$d")
    find $d/apps/* -prune -type d | while read e; do

    app=$(basename "$e")

    # skip daily dev site backups
    if ([[ "$app" =~ ^(dev|staging) ]] || [[ "$app" =~ (dev|staging)$ ]]) && [[ "$type" == "daily" ]] ; then
    continue
    fi


    cd $d/apps
    mkdir -p $destination/$user/apps
    archive=$destination/$user/apps/$app.tgz
    @@ -44,7 +55,11 @@ find /srv/users/* -prune -type d | while read d; do
    done
    done

    find /etc/apache-sp/vhosts.d/*.d/*.conf ! -name "main.conf" -exec tar -rvf $tmp_dir/sp-config.tar {} \;
    find /etc/nginx-sp/vhosts.d/*.d/*.conf ! -name "main.conf" -exec tar -rvf $tmp_dir/sp-config.tar {} \;
    find /etc/nginx-sp/ssl/ -type f -exec tar -rvf $tmp_dir/sp-config.tar {} \;


    s3cmd put --recursive $tmp_dir/* s3://$BUCKET/

    rm -fr $tmp_dir
    rm -fr $tmp_dir
  9. @jstnkrr jstnkrr renamed this gist Sep 25, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. @jstnkrr jstnkrr revised this gist Sep 25, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions S3 backup for SP
    Original file line number Diff line number Diff line change
    @@ -46,3 +46,5 @@ done


    s3cmd put --recursive $tmp_dir/* s3://$BUCKET/

    rm -fr $tmp_dir
  11. @jstnkrr jstnkrr created this gist Sep 25, 2015.
    48 changes: 48 additions & 0 deletions S3 backup for SP
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    #/bin/bash

    export BUCKET=filament-sp-backup/counsel-toronto

    date_daily=`date +"%Y-%m-%d"`
    tmp_dir=/tmp/sp-backup-$date_daily

    # Get current month and week day number
    month_day=`date +"%d"`
    week_day=`date +"%u"`

    # On first month day do
    if [ "$month_day" -eq 1 ] ; then
    destination=$tmp_dir/monthly/$date_daily
    else
    # On saturdays do
    if [ "$week_day" -eq 6 ] ; then
    destination=$tmp_dir/weekly/$date_daily
    else
    # On any regular day do
    destination=$tmp_dir/daily/$date_daily
    fi
    fi

    rm -fr $destination/*

    s3cmd sync --recursive --preserve /var/lib/automysqlbackup/ s3://$BUCKET/db/

    shopt -s dotglob
    find /srv/users/* -prune -type d | while read d; do

    user=$(basename "$d")
    find $d/apps/* -prune -type d | while read e; do

    app=$(basename "$e")

    cd $d/apps
    mkdir -p $destination/$user/apps
    archive=$destination/$user/apps/$app.tgz
    echo "$e => $archive"

    tar cvzfp $archive $e

    done
    done


    s3cmd put --recursive $tmp_dir/* s3://$BUCKET/