Daily Database backup using Cron Job

谁说我不能喝 提交于 2019-12-03 19:13:32

问题


Hi i want to take database backup at daily mid night using cron job... and the name of database backup should append with current date... the format of backup file should be mydata_yyyy_mm_dd.sql ... backup file should be placed in /root directory


回答1:


something like

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

should work.

Please read

  • man date
  • man 5 crontab



回答2:


Create a cron.sh file with this content:

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

And give the Read permission or full access permission for that cron.sh file.

and add this line into crontab file ($ crontab -e)

 0 0 * * *   cron.sh


来源:https://stackoverflow.com/questions/6578533/daily-database-backup-using-cron-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!