A Simple Bash Script for MySQL Database Backup An Advance Bash Script for MySQL Database Backup

Backup MySQL Databases to S3

1. Install AWS CLI

In order to use this script, the system must have AWS CLI installed. https://tecadmin.net/installing-aws-cli-in-linux/

2. Create S3 Bucket

Login to AWS Management Console and create a new s3 bucket. Alternatively, you can also create s3 bucket via AWS CLI. The command will be like: Just replace the bucket name and region.

3. Shell Script to Backup MySQL database to S3

Create a file like /backup/scripts/s3-backup-mysql.sh in edit your favorite text editor. Then add the below content:

Update all the necessary variables as per your system environment.

4. How to run backup script

Set the execute (x) permission on script: Then run the backup script.

5. Schedule backup script to run daily

Schedule the shell script using crontab to run on a daily basis. Add the below settings to end of the file: Save the file and close it.

Conclusion