================================================================================ Tutorial : Backup MySQL Database to EOS on Linux Server ================================================================================ ************ Introduction ************ 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. ************* Prerequisites ************* 1. Bucket in E2E Object Store with Necessary Permissions. If you have not created a bucket yet, please refer `Getting Started Guide `_ 2. Access and Secret keys with Admin permissions for the target bucket 3. Linux Server with Root access 4. Mysql Databases credentials 5. 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 :: vim mysqlbackup.sh 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/* .. Note:: 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 :: ./mysqlbackup.sh 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 :: crontab -e Add below Line to backup you script Weekly once :: 0 0 * * 0 bash /opt/scripts/mysqlbackup.sh to >/dev/null 2>&1 Conclusion ========== 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.