-
-
Save azaitsev/1e5ff7c2424f231c618bd493d6c4bcc2 to your computer and use it in GitHub Desktop.
Revisions
-
azaitsev revised this gist
Aug 10, 2022 . 1 changed file with 3 additions and 3 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 @@ -48,18 +48,18 @@ su - postgres -c "pg_dump -Fc ${DB} > ${DUMPDIR}/${FILENAME}" SHA1=$(sha1sum ${DUMPDIR}/${FILENAME} | sed -En "s/^([0-9a-f]{40}).*/\1/p") #log in to backblaze /usr/local/bin/b2 authorize-account ${B2_ACCOUNT_ID} ${B2_APP_KEY} # upload it /usr/local/bin/b2 upload-file --sha1 ${SHA1} \ ${INFO} \ --noProgress \ ${BUCKET} \ ${DUMPDIR}/${FILENAME} \ ${FILENAME} #log out /usr/local/bin/b2 clear-account # make sure file still exists and clean it up -
azaitsev revised this gist
Jul 14, 2022 . 1 changed file with 1 addition 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 @@ -34,6 +34,7 @@ FILENAME=${DB}_$(date +%Y-%m-%d).dump INFO="--info app=${DB} --info db=${DB}" mkdir -p ${DUMPDIR} chown postgres:postgres -R ${DUMPDIR} # cleanup any old backups if [ -f "${DUMPDIR}/${FILENAME}" ]; then -
azaitsev revised this gist
Jul 14, 2022 . 1 changed file with 1 addition and 1 deletion.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 @@ -27,7 +27,7 @@ echo "Backing up db ${DB} to bucket ${BUCKET}." source $3 DUMPDIR="/tmp/${DB}" #will look like: app_db_2017-12-31.dump FILENAME=${DB}_$(date +%Y-%m-%d).dump -
azaitsev revised this gist
Jul 14, 2022 . 1 changed file with 9 additions and 11 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 @@ -3,14 +3,13 @@ # pass 4 args: # - database name (needs to exist in postgres) # - bucket name (target of the upload) # - file containing b2 credentials (it will be sourced and needs to set B2_ACCOUNT_ID and B2_APP_KEY) # # example: ./pg_b2_backup.sh db backups-daily ~/b2_creds # # example for a daily cron job backing up database "db" of app "app" to b2 bucket "daily-backups": # 20 4 * * * cd ~/scripts && ./pg_b2_backup.sh db daily-backups ~/b2_creds &>> ~/logs/backups.log set -e @@ -23,17 +22,16 @@ if [ "$EUID" -ne 0 ]; then fi DB=$1 BUCKET=$2 echo "Backing up db ${DB} to bucket ${BUCKET}." source $3 DUMPDIR="/tmp/${DB}/" #will look like: app_db_2017-12-31.dump FILENAME=${DB}_$(date +%Y-%m-%d).dump INFO="--info app=${DB} --info db=${DB}" mkdir -p ${DUMPDIR} @@ -43,7 +41,7 @@ if [ -f "${DUMPDIR}/${FILENAME}" ]; then fi # dump it su - postgres -c "pg_dump -Fc ${DB} > ${DUMPDIR}/${FILENAME}" # calculate sha1 sum SHA1=$(sha1sum ${DUMPDIR}/${FILENAME} | sed -En "s/^([0-9a-f]{40}).*/\1/p") -
schnapster created this gist
Jan 21, 2018 .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,69 @@ #!/bin/bash # this requires the backblaze CLI tool to be installed (pip install b2) # pass 4 args: # - database name (needs to exist in postgres) # - app name (meta information) # - bucket name (target of the upload) # - file containing b2 credentials (it will be sourced and needs to set B2_ACCOUNT_ID and B2_APP_KEY) # # example: ./pg_b2_backup.sh db app backups-daily ~/b2_creds # # example for a daily cron job backing up database "db" of app "app" to b2 bucket "daily-backups": # 20 4 * * * cd ~/scripts && ./pg_b2_backup.sh db app daily-backups ~/b2_creds &>> ~/logs/backups.log set -e echo $(date) # Verify we are root if [ "$EUID" -ne 0 ]; then echo "Please run as root" exit 1 fi DB=$1 APP=$2 BUCKET=$3 echo "Backing up db ${DB} of app ${APP} to bucket ${BUCKET}." source $4 DUMPDIR="/tmp" #will look like: app_db_2017-12-31.dump FILENAME=${APP}_${DB}_$(date +%Y-%m-%d).dump INFO="--info app=${APP} --info db=${DB}" mkdir -p ${DUMPDIR} # cleanup any old backups if [ -f "${DUMPDIR}/${FILENAME}" ]; then rm -f "${DUMPDIR}/${FILENAME}" fi # dump it su - postgres -c "pg_dump ${DB} > ${DUMPDIR}/${FILENAME}" # calculate sha1 sum SHA1=$(sha1sum ${DUMPDIR}/${FILENAME} | sed -En "s/^([0-9a-f]{40}).*/\1/p") #log in to backblaze b2 authorize-account ${B2_ACCOUNT_ID} ${B2_APP_KEY} # upload it b2 upload-file --sha1 ${SHA1} \ ${INFO} \ --noProgress \ ${BUCKET} \ ${DUMPDIR}/${FILENAME} \ ${FILENAME} #log out b2 clear-account # make sure file still exists and clean it up if [ -f "${DUMPDIR}/${FILENAME}" ]; then rm -f "${DUMPDIR}/${FILENAME}" fi