--- title: Backup MySQL Database to EOS --- # 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. If you have not created a bucket yet, please refer to [Getting Started](/docs/myaccount/storage/object_storage/intro#create-a-bucket) section. 2. Access and Secret keys with permissions on the target bucket 3. Linux Server with Root access 4. MySQL database credentials. 5. Setting up s3cmd on your server. If you haven't set it up, please refer to the tutorial: [Setting up s3cmd](/docs/myaccount/storage/object_storage/setting_up_s3cmd). ## Step 1: Configure Backup Script The shell script provided below is used to back up your database and upload it to S3. Copy and paste the script below on your server with the filename `mysqlbackup.sh`. To create a file: ``` vim mysqlbackup.sh ``` Edit the below script and add your **database credentials**, **Bucketname** and **your backup location details** ```bash #!/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/* ``` :::info 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 is working ``` ./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 schedule 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 command ``` crontab -e ``` Add below Line to backup your script weekly ``` 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 issues while configuring the same and need assistance, you can contact [cloud-Platform@e2enetworks.com](mailto:cloud-Platform@e2enetworks.com) where our team can assist you. ---