Skip to content

Instantly share code, notes, and snippets.

@philfreo
Created April 6, 2012 17:58
Show Gist options
  • Select an option

  • Save philfreo/2321650 to your computer and use it in GitHub Desktop.

Select an option

Save philfreo/2321650 to your computer and use it in GitHub Desktop.

Revisions

  1. philfreo revised this gist Apr 23, 2012. 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
    @@ -14,13 +14,13 @@ DB_HOST=$SLAVE
    DB_NAME=""
    DB_USER=""
    DB_PASS=""
    FILE_NAME="db-$(date +%Y-%m-%d-%H:%M).sql"
    FILE_NAME="db-$(date +%Y-%m-%d-%H:%M).sql.gz"

    # save only encrypted version
    #mysqldump -u ${DB_USER} -p${DB_PASS} -h ${DB_HOST} ${DB_NAME} | openssl aes-256-cbc -salt -e -pass file:/path/to/password.txt > /path/to/backups-enc/${FILE_NAME}.enc
    #mysqldump -u ${DB_USER} -p${DB_PASS} -h ${DB_HOST} ${DB_NAME} | gzip -c | openssl aes-256-cbc -salt -e -pass file:/path/to/password.txt > /path/to/backups-enc/${FILE_NAME}.enc

    # save unencrypted version
    mysqldump -u ${DB_USER} -p${DB_PASS} -h ${DB_HOST} ${DB_NAME} > /path/to/backups/${FILE_NAME}
    mysqldump -u ${DB_USER} -p${DB_PASS} -h ${DB_HOST} ${DB_NAME} | gzip -c > /path/to/backups/${FILE_NAME}

    # encrypt the version that gets backed up offsite
    cat /path/to/backups/${FILE_NAME} | openssl aes-256-cbc -salt -e -pass file:/path/to/password.txt > /path/to/backups-enc/${FILE_NAME}.enc
  2. philfreo created this gist Apr 6, 2012.
    26 changes: 26 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/bin/sh

    # CRON
    ## delete encrypted backups older than 5 days
    #55 3 * * * find /path/to/backups-enc -mtime +5 -exec rm {} \;
    ## delete un-encrypted backups older than 1 days
    #55 3 * * * find /path/to/backups -mtime +0 -exec rm {} \;
    ## database dump at 4am UTC = 8pm PST (9pm PDT)
    #0 4 * * * /path/to/this/script

    MASTER="YYYY.us-west-1.rds.amazonaws.com"
    SLAVE="XXXX.us-west-1.rds.amazonaws.com"
    DB_HOST=$SLAVE
    DB_NAME=""
    DB_USER=""
    DB_PASS=""
    FILE_NAME="db-$(date +%Y-%m-%d-%H:%M).sql"

    # save only encrypted version
    #mysqldump -u ${DB_USER} -p${DB_PASS} -h ${DB_HOST} ${DB_NAME} | openssl aes-256-cbc -salt -e -pass file:/path/to/password.txt > /path/to/backups-enc/${FILE_NAME}.enc

    # save unencrypted version
    mysqldump -u ${DB_USER} -p${DB_PASS} -h ${DB_HOST} ${DB_NAME} > /path/to/backups/${FILE_NAME}

    # encrypt the version that gets backed up offsite
    cat /path/to/backups/${FILE_NAME} | openssl aes-256-cbc -salt -e -pass file:/path/to/password.txt > /path/to/backups-enc/${FILE_NAME}.enc