Daily Database backup using Cron Job

后端 未结 2 1685
不知归路
不知归路 2020-12-29 11:34

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

相关标签:
2条回答
  • 2020-12-29 11:55

    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
    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题