MySQL Backup Script in Perl for Linux

This backup script requires Perl to be installed. The default version that comes with your Linux distribution will probably work fine. Check whether you have perl packages installed with the command rpm -qa | grep perl

This script is capable of creating MySQL backup files, compressing the backups, deleting old backups and sending an email when encountering an error.

Edit it to supply your MySQL credentials and adjust the parameters to your requirements.

Schedule it to run with crontab. I recommend a daily full backup.

e.g. Your crontab may look like this to run every day at 8am:

0 8 * * * /usr/bin/perl /home/apps/scripts/mysql_backup.pl FULL

Do not run this script as root. That is unsafe.

A FULL backup will produce a zip file containing a MySQL Dump SQL file. To use the incremental backup method, specify the string INC instead of FULL at the end of the crontab line. An INC backup (short for incremental) will simply flush the binary logs which means that all transactions still in memory will be written to a binary log file and then a new binary log file will become the current one. You should backup those binary log files , normally found in the MySQL Data directory, as part of your backup procedures in case you want to restore to a particular point in time in the future. Typically incremental backup jobs are run every hour in order to produce up to 23 incremental backups (binary log files) per day which is manageable and not a headache to restore if you ever needed to restore them.

MySQL Backup Script for Linux in Perl

Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *