I'm goint to show you how to set up an automatic mySQL backup script using Shell script, Perl and CRON.
First of all, we must create an user with the minimum privileges for using only mysqldump so I will set the LOCK TABLES privilege for the database which I want to dump. The command I use is:
mysqldump -uUSER -pPASSWORD --opt DATABASE > /backupfile.sql
Next step is to compress the resulting file, por example using
tar -czf BACKUPFILECOMPRESSED.tar.gz backupfile.sql
Now we can move our file wherever we want or sent it by email...
The final step is to include the script into the cron config file /etc/crontab. FOr example, I want to execute my scripts from Monday to Saturday three times per day at 11:15, 14:15 and 18:15.
15 11,14,18 * * 1-6 USER /PATH/SCRIPT
restart the cron services
/etc/init.d/cron restart
and done!.
Hope help
No comments:
Post a Comment