Database backup is one of the most important tasks of server maintenance. Taking database backup in a Linux server manually whenever we want a backup in not for cools users :D. Database backup should be taken periodically in fixed intervals, and we here like to automate out periodic tasks. In this tutorial we will take a look at Cron Jobs and Crontabs in Linux; and see how we can schedule periodic complete Database backups of our MySQL Databases using Cron.
Alright so let’s get into it:
MySQL Database Backup in Linux |
1. Install Cron
Cron should be installed as a part of base system, but due to some issues it may not be available for you. Type crontab -a in your terminal and hit enter, if you see crontab command not found then you need to install crontab. If your system is Debian, then you can install Cron using :
If you are using a Redhat based system, use:
Running Cron job Yearly
@yearly /scripts/script.sh
Running Cron job Monthly
@monthly /scripts/script.sh
Running Cron job Weekly
@weekly /bin/script.sh
Running Cron job Daily
@daily /scripts/script.sh
Running Cron job Hourly
@hourly /scripts/script.sh
Running Cron job on Reboot
@reboot /scripts/script.sh
Running Cron job at 5AM Daily
0 5 * * * /bin/sh backup.sh
Running Cron job at 12AM & 12PM Daily
0 12,24 * * * /scripts/script.sh
Running Cron job Every Minute
* * * * * /scripts/monitor.sh
Running Cron job Every Monday at 2AM
0 2 * * mon /scripts/script.sh
Running Cron job Every 30 Minutes
*/30 * * * * /scripts/monitor.sh
Running Cron job Every 2 Hours
0 */5 * * * /scripts/script.sh
Running Cron job Every 30 Seconds
* * * * * /scripts/script.sh
* * * * * sleep 30; /scripts/script.sh
Running Cron job on Selected Months
* * * jan, mar, april, jun * /script/mons.sh
Running Cron job on Selected Days at 3PM
0, 15 * * sun, wed /script/check.sh
Running Cron job on first Sunday of every Month
0 2 * * sun [ $(date +%d) -le 07 ] && /script/script.sh
Running Multiple Scripts in a Single cron
* * * * * /scripts/script.sh; /scripts/scrit2.sh
where do I create crontab