Trending News

Blog

How To Use A Simple Bash Script To Backup MySQL Database
Database

How To Use A Simple Bash Script To Backup MySQL Database 

Q. How do I back up my MySQL database on a regular basis? A bash script for backing up MySQL databases. In this tutorial, you will learn how to use a simple bash script to take a MySQL database backup, archive it, and store it locally.

Bash script to backup MySQL database

This script would also free up storage space by removing older backups. You can decide how long the backup should be held on a local disk. This tutorial can also be used to back up a MySQL database and store a copy on a remote FTP server.

Create a backup script for MySQL

Copy the following content into a script file (for example, /backup/mysql-backup.sh) and save it to your Linux system. This link will take you to a page where you can download the script. Then, according to your environment, adjust any configuration values in the script’s section “Update below values.”

Be sure to set execute permission after creating or downloading a script in order for it to run properly.

Now Schedule The Script In Crontab

Now, in crontab, schedule the script to run every day and perform a backup on a regular basis. With the crontab -e command, you can edit your system’s crontab. To allow backup at 2 a.m., add the following settings.

Now save the crontab file. After enabling cron, the script can take backups automatically. But, you can double-check backups on a weekly or monthly basis to ensure that they are working.

Related posts

Leave a Reply

Required fields are marked *