MySQL database backup with Cron

After creating two different MySQL database backup tools in Python here and here, we can improve the database backups by automating them. This is where Cronjobs come in handy. Cronjobs are available on Unix-like systems and make it possible to execute commands on specified times or time intervals.

What we’re going to do here is running our MySQL database backup script every 5 hours. In this tutorial I’m using this Python script.

First we’ll have to slightly modify our Python script to make this possible. Change the main function to immediately start the backup, without confirmation. The new main function will look like this:

When this is changed, we can add the cronjob.

Run the following command in your terminal to open crontab in a text editor.

Add the following line to the bottom of the file.

This will run the backup script every 5 hours.

Leave a Reply

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

Protected with IP Blacklist CloudIP Blacklist Cloud