Tutorial : Backup MySQL Database to EOS on Linux Server¶
In MySQL, Regular backups of your Mysql data are very important to protect it from data loss. There are several types of backup options available, Here in this tutorial we will show you an easy way to backup your Mysql Database to EOS for a regular interval backup using Linux s3cmd Bash script.
Bucket in E2E Object Store with Necessary Permissions. If you have not created a bucket yet, please refer Getting Started Guide
Access and Secret keys with Admin permissions for the target bucket
Linux Server with Root access
Mysql Databases credentials
Setting up s3cmd on your server. If you haven’t setup please refer Tutorial: Setting up s3cmd
Step1 : Configure Backup script¶
The shell script provided below is used to backup your database and upload it to S3. Copy Paste the below script on your server with the filename as mysqlbackup.sh
To Create a file
Edit the below script and add your database credentials, Bucketname and your backup location details
#!/bin/bash #Enter the details below # Database credentials USER="Username" PASSWORD="YourPassword" HOST="localhost" DBNAME="DatabaseName" #Enter the Bucket details S3BUCKET="s3://YourBucketName" #Backup_Details LOCATION="/tmp/backups" TIMESTAMP=$(date +"%d-%b-%Y-%H:%M:%S") #---------------------------------------------# #Basic Script mysqldump -h$HOST -u$USER -p$PASSWORD $DBNAME | gzip -9 > $LOCATION/$DBNAME-$TIMESTAMP.sql.gz s3cmd sync -r $LOCATION/* $S3BUCKET/ rm -rf $LOCATION/*
The above script is a Basic Script configured as an Example,You can modify it as per your Need.
Step 2 : Make the backup script Executable¶
chmod +x mysqlbackup.sh
Run the script to make sure it’s all good
If the above scripts run fine,Then your script is Now ready.We can now schedule it with Cron
Step 3 : Schedule it with Cron¶
Now, We can Schdule the BackupScript to Run it Daily or on Weekly basis as per our requirement. Assuming the backup script is available on /opt/scripts ,Edit the crontab file and add below Line
To Edit the Crontab File,You can use below comman
Add below Line to backup you script Weekly once
0 0 * * 0 bash /opt/scripts/mysqlbackup.sh to >/dev/null 2>&1
Now you have your Database backup (Dump) in your EOS Bucket.If you face any issue while configuring the same and need some assistance, You can contact cloud-Platorm@e2enetworks.com where our team can assist you on it.