Last active
August 20, 2021 05:11
-
-
Save bil9000/62af751362fdf932612e2312c6a56487 to your computer and use it in GitHub Desktop.
rds-to-s3-backup
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 | |
DT=$(date +%Y-%m-%d) | |
PASS=$(aws secretsmanager get-secret-value --secret-id testdb01-password --query SecretString --output text) | |
for DB in $(mysql -h db1-DBNAME-instance-1.INSTANCEID.us-east-1.rds.amazonaws.com -uadmin -p$PASS -e 'show databases' -s --skip-column-names); do | |
mysqldump -h db1-DBNAME.cluster-INSTANCEID.us-east-1.rds.amazonaws.com -uadmin -p$passwd $DB > $DB.sql | |
echo "$DB database dumped" | |
tar -zcvpf $DB.sql.tar.gz $DB.sql | |
echo "$DB database zipped" | |
aws s3 cp $DB.sql.tar.gz s3://S3BUCKETNAME/$DT/$DB.sql.tar.gz | |
echo "uploaded $DB to s3" | |
rm $DB.sql | |
rm $DB.sql.tar.gz | |
echo "$DB dbbackup files delted" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment