Daily database backup using Cron job

Hi, I want to take a database backup daily in the middle of the night using the cron job ... and the database backup name should be added with the current date ... the backup file format should be mydata_yyyy_mm_dd.sql ... backup file should be placed in the / root directory

+8
linux mysql cron crontab crontrigger
source share
2 answers

something like

0 0 * * * /path/to/mysqldump ... > /path/to/backup/mydata_$( date +"%Y_%m_%d" ).sql 

must work.

Read please

  • man date
  • man 5 crontab
+17
source share

Create a cron.sh file with this content:

  mysqldump -u root -p{PASSWORD} DBNAME 2>> "/filename_`date '+%Y-%m-%d'`.sql" 

And grant read permission or full permission for this cron.sh file.

and add this line to the crontab file ($ crontab -e)

  0 0 * * * cron.sh 
+4
source share

All Articles