Skip to content

Instantly share code, notes, and snippets.

@akumbhani66
Created September 24, 2020 12:38
Show Gist options
  • Save akumbhani66/6621ad82490dfd1c5b2bbc6ee495eb15 to your computer and use it in GitHub Desktop.
Save akumbhani66/6621ad82490dfd1c5b2bbc6ee495eb15 to your computer and use it in GitHub Desktop.
#vim mysqlbackupS3.sh
#!/bin/bash
DB_NAME="faprod"
TSTAMP=$(date +"%d-%b-%Y-%H-%M-%S")
S3BUCKET="s3://sfo2.digitaloceanspaces.com"
#logging
LOG_ROOT="./dump.log"
#Dump of Mysql Database into S3\
echo "$(tput setaf 2)creating backup of database start at $TSTAMP" >> "$LOG_ROOT"
mysqldump --user=root --databases faprod > ./backups/$DB_NAME-$TSTAMP.sql
echo "$(tput setaf 3)Finished backup of database and sending it in S3 Bucket at $TSTAMP" >> "$LOG_ROOT"
#Delete files older than 15 days
find ./backups/* -mtime +15 -exec rm {} \;
s3cmd put ./backups s3://name-of-space --recursive
echo "$(tput setaf 2)Moved the backup file from local to S3 bucket at $TSTAMP" >> "$LOG_ROOT"
echo "$(tput setaf 3)Coll!! Script have been executed successfully at $TSTAMP" >> "$LOG_ROOT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment