Last active
October 5, 2016 13:35
Revisions
-
yuryroot renamed this gist
Jul 24, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
yuryroot revised this gist
Jun 22, 2015 . No changes.There are no files selected for viewing
-
yuryroot revised this gist
Jun 22, 2015 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,11 +7,11 @@ # * SCP_HOST # * SCP_DIR # # Also optional variable MAIL_TO can be specified. # # For example: # WORKING_DIR=/tmp/db_backup/ PG_USER=postgres SCP_USER=name SCP_HOST=localhost SCP_DIR=uploads ./db_backup.sh # MAIL_TO=email@address.com WORKING_DIR=/tmp/db_backup/ PG_USER=postgres SCP_USER=name SCP_HOST=localhost SCP_DIR=uploads ./db_backup.sh TIMESTAMP=$(date +%Y_%m_%d) BACKUP_NAME="${TIMESTAMP}_pg_basebackup" @@ -32,9 +32,9 @@ exit_unless_success() { } send_mail() { if [ -n "$MAIL_TO" ]; then log "Sending email to $MAIL_TO..." mail -s "$1" $MAIL_TO < /dev/null fi } -
yuryroot revised this gist
Jun 19, 2015 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,8 +7,11 @@ # * SCP_HOST # * SCP_DIR # # Also optional variable EMAIL_ADDRESS can be specified. # # For example: # WORKING_DIR=/tmp/db_backup/ PG_USER=postgres SCP_USER=name SCP_HOST=localhost SCP_DIR=uploads ./db_backup.sh # EMAIL_ADDRESS=email@address.com WORKING_DIR=/tmp/db_backup/ PG_USER=postgres SCP_USER=name SCP_HOST=localhost SCP_DIR=uploads ./db_backup.sh TIMESTAMP=$(date +%Y_%m_%d) BACKUP_NAME="${TIMESTAMP}_pg_basebackup" @@ -23,10 +26,18 @@ log() { exit_unless_success() { exit_code=$? if [ $exit_code -ne 0 ]; then send_mail "[$BACKUP_NAME] An unknown error occurred while creating backup. Exit code: $exit_code" exit $exit_code fi } send_mail() { if [ -n "$EMAIL_ADDRESS" ]; then log "Sending email to $EMAIL_ADDRESS..." mail -s "$1" $EMAIL_ADDRESS < /dev/null fi } if [ ! -d "$WORKING_DIR" ]; then mkdir -p "$WORKING_DIR" exit_unless_success @@ -52,3 +63,6 @@ exit_unless_success log "Cleaning..." rm -rf $BACKUP_NAME* exit_unless_success send_mail "[$BACKUP_NAME] Database backup was successfully created." -
yuryroot revised this gist
Jun 19, 2015 . 1 changed file with 14 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,16 @@ #!/usr/bin/env bash # These ENV variables should be specified: # * WORKING_DIR # * PG_USER # * SCP_USER # * SCP_HOST # * SCP_DIR # # For example: # WORKING_DIR=/tmp/db_backup/ PG_USER=postgres SCP_USER=name SCP_HOST=localhost SCP_DIR=uploads ./db_backup.sh TIMESTAMP=$(date +%Y_%m_%d) BACKUP_NAME="${TIMESTAMP}_pg_basebackup" ARCHIVE_NAME="$BACKUP_NAME.tar.gz" SPLIT_NAME_PREFIX="${ARCHIVE_NAME}_" @@ -39,6 +46,9 @@ log "Splitting archive by parts of $SPLIT_SIZE..." split -b $SPLIT_SIZE $ARCHIVE_NAME $SPLIT_NAME_PREFIX exit_unless_success log "Uploading to remote server..." scp $SPLIT_NAME_PREFIX* $SCP_USER@$SCP_HOST:$SCP_DIR exit_unless_success log "Cleaning..." rm -rf $BACKUP_NAME* -
yuryroot revised this gist
Jun 19, 2015 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -38,3 +38,7 @@ exit_unless_success log "Splitting archive by parts of $SPLIT_SIZE..." split -b $SPLIT_SIZE $ARCHIVE_NAME $SPLIT_NAME_PREFIX exit_unless_success log "Removing uncompressed basebackup..." rm -rf $BACKUP_NAME exit_unless_success -
yuryroot created this gist
Jun 19, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ #!/usr/bin/env bash PG_USER="postgres" TIMESTAMP=$(date +%Y_%m_%d) WORKING_DIR="/home/usgene/db_backup" BACKUP_NAME="${TIMESTAMP}_pg_basebackup" ARCHIVE_NAME="$BACKUP_NAME.tar.gz" SPLIT_NAME_PREFIX="${ARCHIVE_NAME}_" SPLIT_SIZE="10G" log() { echo "[$(date)] $1" } exit_unless_success() { exit_code=$? if [ $exit_code -ne 0 ]; then exit $exit_code fi } if [ ! -d "$WORKING_DIR" ]; then mkdir -p "$WORKING_DIR" exit_unless_success fi cd $WORKING_DIR log "Creating basebackup..." pg_basebackup -U $PG_USER --pgdata=$BACKUP_NAME --xlog-method=stream exit_unless_success log "Compressing backup..." tar -czf $ARCHIVE_NAME $BACKUP_NAME exit_unless_success log "Splitting archive by parts of $SPLIT_SIZE..." split -b $SPLIT_SIZE $ARCHIVE_NAME $SPLIT_NAME_PREFIX exit_unless_success