Created
February 26, 2019 06:53
-
-
Save samber/04b4c348f2c0cddf0b8cfaa82d4bf070 to your computer and use it in GitHub Desktop.
Script for backuping db
This file contains 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 characters
#!/bin/bash | |
#set -x | |
set -e | |
export AWS_ACCESS_KEY_ID="xxxxxxxxxxxxxxx" | |
export AWS_SECRET_ACCESS_KEY="xxxxxxxxxxxxxxxxx" | |
export AWS_DEFAULT_REGION="eu-central-1" | |
export BUCKET="a-b-c-backups" | |
export DATE=$(date +%Y-%m-%d) | |
#export DATE=$(date +%Y-%m-%d--%H-%M-%S) | |
export FILENAME="dump.${DATE}.sql" | |
# this is not suppression date, but cache expiration date | |
export EXPIRES=$(date --iso-8601=seconds -d '1 month') | |
if [[ $(date '+%u') = 6 ]]; then | |
# saturday morning backups expires 1y later | |
export EXPIRES=$(date --iso-8601=seconds -d '1 year') | |
fi | |
rm -rf /tmp/${FILENAME} | |
docker pull xueshanf/awscli | |
cd /root/docker/bienavous && /usr/local/bin/docker-compose exec -T postgres pg_dump -U username db_name > /tmp/${FILENAME} | |
docker run --rm -i \ | |
-v /tmp:/data \ | |
-e AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID} \ | |
-e AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY} \ | |
-e AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION} \ | |
xueshanf/awscli \ | |
aws s3 cp /data/${FILENAME} s3://${BUCKET}/bienavous-pg/${FILENAME} \ | |
--expires ${EXPIRES} --storage-class STANDARD_IA | |
rm -rf /tmp/${FILENAME} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
crontab: