How to setup cron for TestLink DB backup?
Introduction
We can set up a backup script for TestLink DB using mysqldump utility and drop an entry in crontab to automatically schedule the backup.
Example backup script:
The script does a backup with mysqldump utility, Maintains a 7 days backup, and deletes older files. Please feel free to increase the number. The mysqldump utility performs logical backups, producing a set of SQL statements that can be executed to reproduce the original database object definitions and table data. It dumps one or more MySQL databases for backup or transfers to another SQL server.
Script Code
Below is the sample backup script:
cd /opt/lampstack/mysql/bin ./mysqldump -u root -p testlink > /opt/lampstack/TestLinkBackup/testlink_backup`date +"%d%m%y"`.sql ./mysqldump -u root -p testlink > /opt/lampstack/TestLinkBackup/testlink_backup`date +"%d%m%y"`.dump find /opt/lampstack/TestLinkBackup/ -type f -mtime +7 | xargs rm -f
Cron vs Crontab
Cron is a daemon that runs at the times of system boot from /etc/init.d scripts. If needed it can be stopped/started/restart using init script or with command service crond start.
Crontab ( cron table ) is a file that contains the schedule of cron entries to be run and at specified times. File location varies on different distributions.
Steps to setup cron:
Create a folder and Copy the backupĀ .sh file
Give execute permissions to the specified user where the cron runs.
Add it to the crontab to execute it daily.
Example:
$> crontab -e
+—————- minute (0 – 59)
| +————- hour (0 – 23)
| | +———- day of month (0 – 30)
| | | +——- month (1 – 12)
| | | | +—- day of week (0 – 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed
0 12 * * * ./<path>/TestlinkBackup.sh
For example : the above command does a backup every day at 12.00 am.
* Note
—————————–
you will find ‘cron.hourly’, ‘cron.daily’, ‘cron.weekly’ and ‘cron.monthly’ files in /etc/
Check that if “crond” daemon is running.
$> service crond status
If it is not running type the following two command to start crond:
$> service crond start