What will be code for adding a Cron for Backing up databases?

Mrinmoy

Active Member
Feb 2, 2019
38
5
8
India
cPanel Access Level
Website Owner
What will be code for adding a Cron for Backing up databases? And I want the the backup file in this format 'dd-mm-yy.sql.gz', so what should be the code?
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,265
1,297
363
Houston
  • Like
Reactions: kadrin

Henry Carter

Active Member
Jul 31, 2019
34
6
8
India
cPanel Access Level
Website Owner
To dump the database with .sql.gz format use the below command
mysqldump -u username -pPassword dbname | gzip > backup_db_`date +%F`.sql.gz

Save it as a sh file for eg: mysqlbackup.sh and then set a cron like below to execute the cron on every Saturday on 00:00 hours. Edit the cron settings based on your requirement.
0 0 * * 6 /bin/sh /root/mysqlbackup.sh